-
Notifications
You must be signed in to change notification settings - Fork 47.4k
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
Allow the length of the dependency array in hooks to change. #20850
Conversation
Comparing: 8af27ae...47cc182 Critical size changesIncludes critical production bundles, as well as any change greater than 2%:
Significant size changesIncludes any change greater than 0.2%: Expand to show
|
a2a8e49
to
d6e11ef
Compare
After a bit of testing I think the warning is more annoying than useful, however I can't use log levels below warn. I have a silent version at /lbfalvy/react/tree/nowarn. |
Allow length of dependencies array to change.
This pull request has been automatically marked as stale. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize reviewing it yet. Your contribution is very much appreciated. |
Bump: this is very useful functionality that would solve a lot of pain points I've encountered. |
This is very old now and I don't have the patience to fix it, and it can cause very subtle bugs as described in the issue, but I made a special hook for variable length arrays here @lbfalvy/react-utils which somewhat imporves on the situation by making the variable length opt-in. |
This pull request has been automatically marked as stale. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize reviewing it yet. Your contribution is very much appreciated. |
Apologies for closing. We've accidentally pushed a master branch to the repo (due to an old fork), then deleted it, and this lead to a bunch of PRs getting auto-closed. GitHub seems confused and unfortunately does not offer a way to reopen this against That said, I don't think we will be adding support for this. (Thanks for PR though) |
Summary
Allow for hooks to depend on the content of variable-length arrays.
This is currently impossible since both the number of hooks and the number of dependencies per hook are fixed numbers.
The only case where dependency array comparison can still have misleading results is
[...myArray, ...myOtherArray]
, so I also added a warning about this. This may be superfluous as the warning appears in a lot of what would now become perfectly valid situations.resolves #18229
Test Plan
As shown in the edited test case,
useEffect(() => etc, myArray)
now yields expected results.