我真的很困惑,我习惯于通过道具分解来创建无状态组件。升级到最新版本的React和Eslint和Webpack之后。突然出现以下错误:
./src/components/Blog/Post.js
Line 4: 'title' is missing in props validation react/prop-types
Line 4: 'description' is missing in props validation react/prop-types
为什么这会停止工作?
我也用支票包裹了道具。仍然出现同样的错误。
我的代码:
import React from 'react';
const Post = props => {
const { title, description } = props;
return (
<article>
<header>
{title && <h2>{props}</h2>}
{description && <p>{description}</p>}
</header>
</article>
);
};
export default Post;
答案 0 :(得分:2)
它们是警告,提醒您添加Typechecking With PropTypes
import PropTypes from 'prop-types';
// ...
// This will remove warnings.
Post.propTypes = {
title: PropTypes.string,
description: PropTypes.string,
};