-
Notifications
You must be signed in to change notification settings - Fork 65
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
Error withforbidExtraProps
and scoped.css?
#51
Comments
What random identifier? Can you provide some example code? |
That looks like a data attribute on an HTML element, not something on the outside click handler component. It's quite necessary, and every component should have it. The rationale is that it avoids bugs - if you meant to pass |
yeah, that's just the example of the Because for every other npm libraries that I'm using, none of them does the prototypes checking. Because essentially, the prototype checking only relevant for the shared component that you're building by yourself. Even in the real practice, you need to remove the prototype in the production file. (correct me if I'm wrong) https://www.npmjs.com/package/babel-plugin-transform-react-remove-prop-types |
You're wrong; React itself doesn't check propTypes in production, but propTypes themselves do always evaluate in production, and it's very tricky to remove them safely. Documentation is not enough whatsoever. Either way, the reason this prop is "extra" is because it has no effect except to perhaps allow you to target it with CSS, and this library very intentionally does not allow you that kind of styling control. |
okay fair enough, you're more experience in React. maybe my last question is why did you use the because |
As far as I know, Airbnb uses that on every single component they have (or the equivalent TypeScript type), and the purpose is to prevent bugs. If you are passing an extra prop, your code is broken. |
Okay, thanks. just last thought of mine, I cannot find a single use case where you pass an extra props and make the code broken. |
I think by default, passing an extra prop to a component is a type error, when the component has prop types defined. |
I use scoped.css where everytime I import the css, it will append some random identifier to the component as the css selector. This will create an error to this library because of the
forbidExtraProps
functionThe text was updated successfully, but these errors were encountered: