简体   繁体   English

更新停止后,React Pros破坏结构了吗?

[英]React props destructuring after updates stopped working?

I am really confused, I am used to to create stateless components with props destructuring. 我真的很困惑,我习惯于通过道具分解来创建无状态组件。 After upgrading to the latest version of React and Eslint and Webpack. 升级到最新版本的React和Eslint和Webpack之后。 Suddenly I am getting the following error: 突然出现以下错误:

./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

Why did this stop working? 为什么这停止工作?

I have also wrapped the props with a check.. and still getting the same error. 我也用支票包裹了道具..并且仍然得到同样的错误。

My code: 我的代码:

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;

They are warnings to remind you to add Typechecking With PropTypes 它们是警告,提醒您添加带有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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM