Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request] PropTypes: validate that no extra props has been passed #8721

Closed
mqklin opened this issue Jan 9, 2017 · 1 comment
Closed

Comments

@mqklin
Copy link

mqklin commented Jan 9, 2017

Here is a stackoverflow question and sorta solution:

componentWillReceiveProps(nextProps) {
  const passedPropNames = Object.keys(nextProps);
  const expectedPropNames = Object.keys(MyComponent.propTypes);
  passedPropNames.forEach(propName => {
    if (!expectedPropNames.includes(propName)) {
      console.warn('Not expecting a property called', propName);
    }
  });
}

It's not working properly at least because there is no recursion, but I hope that the idea is clear.
It can be useful for example after refactoring and helps to eliminate death code, when some props are no longer needed.

@gaearon
Copy link
Collaborator

gaearon commented Jan 9, 2017

Thanks for the suggestion. This issue already exists: #1587.
Please feel free to contribute to the discussion there.

@gaearon gaearon closed this as completed Jan 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants