-
Notifications
You must be signed in to change notification settings - Fork 48.1k
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
Required props provided with cloneElement still display a warning in the console #4494
Comments
This is intentional; validating props at element creation time produces more useful errors. It also more closely matches the behavior of static type systems like Flow. Best for now is to simply mark those props optional. We also may introduce a feature in the future called context that will give another supported way to pass props from a parent like A to a child like B. |
That's what I thought. Thanks @spicyj |
I don't know what was your real use-case @tleunen, but I stumbled upon this issue while implementing a reusable component that had the responsiblity to pass props to its children:
In the end, I worked around the issue with what I found is a more elegant solution:
I like it much better since the dependency of Applied to your Fiddle : https://jsfiddle.net/ap1e9rk3/1/ |
I made an example so it's easier to understand, but basically a warning is displayed in the console because of "missing required props".
The props are given to the element with
React.cloneElement
so I wasn't expecting to get a warning of missing props. I understand this could be an edge case though...https://jsfiddle.net/kdsvgbzu/1/
The text was updated successfully, but these errors were encountered: