-
Notifications
You must be signed in to change notification settings - Fork 47.2k
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
Show a better warning when accidentally returning from constructor #11381
Comments
hi I would like to work on it. Could you please point me to specific direction. I would really appreciate it. |
I think the relevant code is in ReactFiberClassComponent. I would suggest adding a test first (e.g. try to reproduce the existing warning), then try to make changes for a better warning. Does this help? |
Hey, @M-ZubairAhmed, I thought this was a good starting bug and went ahead with the fix as an exercise for myself. If you don't ultimately take this bug, let me know so I can create a pull request. |
@M-ZubairAhmed Have you been able to look at it yet? |
@deanbrophy yes even I have started working on it but since I am a beginner is taking time for me to complete. But I think it's not wise for me to hold it up, you are welcome to continue. |
@M-ZubairAhmed Thanks! The next "good first issue" is yours. |
Maybe it is not related. Basically all the components that we are writing in Class style must deal with the state. Why cannot we enforce returning an initial state in Class style instead of doing |
Because returning something from a constructor already has a (different) meaning in JavaScript. If you're just looking for a terse syntax, use class properties and don't define a constructor at all. |
Fixed in #11395. |
Based on a conversation with @vjeux:
We can fix this to show a different message if
type
has.prototype.isReactComponent
butconstructor()
gave us something without arender
method.The text was updated successfully, but these errors were encountered: