[英]React props destructuring after updates stopped working?
我真的很困惑,我习惯于通过道具分解来创建无状态组件。 升级到最新版本的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;
它们是警告,提醒您添加带有PropType的Typechecking
import PropTypes from 'prop-types';
// ...
// This will remove warnings.
Post.propTypes = {
title: PropTypes.string,
description: PropTypes.string,
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.