facebook / prop-types

Runtime type checking for React props and similar objects
MIT License
4.48k stars 356 forks source link

`checkPropTypes`: add warning for props that not validate in prop-types #272

Closed Zaynex closed 5 years ago

Zaynex commented 5 years ago

Hi, this pull request can help developers to distinguish the props that not validate. Here is example:

function App() {
  const [node, setNode ] = useState(1);
  return <div onClick={() => setNode(Math.random())}>Hi<Child child={'child'} node={node} /></div>
}

class Child extends PureComponent {
  render() {
    console.log('render');
    return <div>{this.props.child}</div>
  }
}
Child.propTypes = {
  child: PropTypes.number,
}

Even if Child component is pureComponent, it still cause Child re-render if unused props change(node in example).

facebook-github-bot commented 5 years ago

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

facebook-github-bot commented 5 years ago

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

Zaynex commented 5 years ago
  1. Already implementation in current version.
  2. break change the default behavior.