-
Notifications
You must be signed in to change notification settings - Fork 47.3k
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
Stateless Component: React.forwardRef make defaultProps invalid #16653
Comments
Could you please use codesandbox.io to make a reproducing example? Or a git repo I can try locally (but preferred codesandbox). Thanks! |
Closing because this issue has insufficient info. |
Here's a CodeSandbox that reproduces the issue. It seems that eslint-plugin-react throws this error:
But it's confusing, since removing the |
Ah, I see why there's confusion here. The function passed to React also logs the following error in the console (as can be seen in your Code Sandbox repro):
|
I just hit on this too. In case anyone else comes across this thread and needs some extra hand-holding (I was still a bit befuddled and it took me a bit to understand):
...but the function returned by
|
By wrapping the component when exporting it, propTypes can't work anymore and we get this kind of warning in console: ``` Warning: forwardRef render functions do not support propTypes or defaultProps. Did you accidentally pass a React component? ``` We need to use the forwardRef as implemented on this PR or as here: https://bit.ly/3ykcWZx More info: facebook/react#16653
By wrapping the component when exporting it, propTypes can't work anymore and we get this kind of warning in console: ``` Warning: forwardRef render functions do not support propTypes or defaultProps. Did you accidentally pass a React component? ``` We need to use the forwardRef as implemented on this PR or as here: https://bit.ly/3ykcWZx More info: facebook/react#16653
It doesn't work for react 18 |
When I add React.forwardRef to a stateless component that is already have defaultProps, It make all defaultProps to undefined?
React.forwardRef can't use with defaultProps ?
react-version: 16.8.6
The text was updated successfully, but these errors were encountered: