dillon1000/react
Commit
Browse files Don't bother comparing constructor when deps are not provided (#14594)
* Don't bother comparing constructor when deps are not provided When no dependencies are passed to an effect hook, what we used to do is compare the effect constructor. If there was no change, then we would skip firing the effect. In practice, this is a useless optimization because the constructor will always be different when you pass an inline closure. And if you don't pass an inline closure, then you can't access any props or state. There are some edge cases where an effect that doesn't close over props or state could be useful, like reference counting the number of mounted components. But those are rare and can be addressed by passing an empty array of dependencies. By removing this "optimization," we can avoid retaining the constructor in the majority of cases where it's a closure that changes on every render. I made corresponding changes to the other hooks that accept dependencies, too (useMemo, useCallback, and useImperativeHandle). * Improve hook dependencies warning It now includes the name of the hook in the message. * Nits
Changed paths5 files
First-parent comparisonpackages/react-dom/src/server/ReactPartialRendererHooks.js ModifiedM packages/react-reconciler/src/ReactFiberHooks.js ModifiedM packages/react-reconciler/src/__tests__/ReactHooks-test.internal.js ModifiedM packages/react-reconciler/src/__tests__/ReactHooksWithNoopRenderer-test.internal.js ModifiedD packages/shared/areHookInputsEqual.js DeletedPatch
Files changed
Rendering syntax-highlighted changes…