Replies: 1 comment 3 replies
-
Yeah this was a bug fix, but I'm not sure if it was intentional that we fixed it. The error shows in 17 if you switch to |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I believe it was alwas unofficially said that effect hooks (e.g.
useEffect
oruseLayoutEffect
) should either return a function or nothing i.e.undefined
.--https://codesandbox.io/s/effect-destroy-function-type-izslc?file=/src/App.js
However, React 17 and 16 did not have a runtime warning when this constraint was broken with
react-dom
nor did it crash when the effect was cleaned up.React 18 will now warn when such a "bad effect" is mounted and crash when that "bad effect" should've been cleaned up.
The source code for React 17 already includes this warning but it seems like it's not actually triggered.
This post isn't necessarily about whether this warning/crash is a useful addition but rather about shining light on the new behavior/bug fix since I haven't heard anyone from the core team talk about it.
Beta Was this translation helpful? Give feedback.
All reactions