-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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
Proposal: react-hooks/exhaustive-deps: a more customizable additionalHooks #18861
Conversation
Hi @dvoytenko! Thank you for your pull request and welcome to our community.We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks! |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit f94be69:
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit d08cd26:
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
Details of bundled changes.Comparing: b41beb1...d08cd26 eslint-plugin-react-hooks
Size changes (stable) |
Details of bundled changes.Comparing: b41beb1...d08cd26 eslint-plugin-react-hooks
Size changes (experimental) |
There's a conflict now because of #18907 |
a7ca524
to
6e45f14
Compare
Thanks, @swissspidy. Rebased. |
Mind updating? Let's get this in. |
6e45f14
to
99b7cb7
Compare
@gaearon Rebased. PTAL. |
I think we might want to think more about the API here. What if you want to use a regex and put it in the map? The existing feature supports regexes. It is also a bit confusing to have two independent options. Why does one of them win? What if a regex matches in one but the key matches in the other one? |
Could be something like
|
Sure. That makes sense. I'll update. |
@gaearon PTAL. I updated per your request. The linter schema is now either one of these:
|
0910d87
to
d08cd26
Compare
@gaearon could you ptal to see if this is good to be merged? |
@gaearon would this be good to go after a rebase? |
Opened #19644 to track this proposal in case it helps with visibility... |
It might be simpler (for end users) to infer the callback index from callsite usage. All the hooks I've ever seen that take a callback have arguments of Are there any callback+deps hooks out in the wild that break this assumption? |
@whatisaphone I think somewhere this was covered as well. Personally, I always order args to have callback and deps as the last 2 (or 1) args. However, the current behavior is exactly the opposite and so we decided to go with a configurable option for backward compatibility. |
I would like to add that
I would say that specifying the index of the callback is a non-complete addition and would suggest to instead specify the index of the DependencyList? |
@MatthijsBon I think you can assume that dependency list is the last argument. I can see why callback may potentially be moved around but that feels like a pretty solid convention thats worth encouraging. |
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 |
Any chance of getting this or #21719 merged? Would love to see this feature. |
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 |
@gaearon Is there a chance of this being merged and shipped? |
@dvoytenko would you be willing to re-create this PR against the |
Quoting #21719 (comment):
|
Summary
The current
additionalHooks
in the react-hooks/exhaustive-deps eslint plugin accepts a regular expression to match hook names. It always assumes the following format:However, this format is not always convenient when other arguments are available in the hook's signature, because the set of dependencies could potentially be large. In those cases, it'd be more convenient to place callback and deps as the last two arguments. For instance, the standard
useImperativeHandle
has an additional first argument:To enable this, the proposal adds a new property:
additionalHooksMap
that takes a map keyed by a hook name and value specifyingcallback
argument offset.An example:
Test Plan
Added new tests for the new format to the eslint tests.