简体   繁体   中英

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

import PropTypes from 'prop-types';

// ...

// This will remove warnings.
Post.propTypes = {
  title: PropTypes.string,
  description: PropTypes.string,
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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