let react-hooks/exhaustive-deps additionalHooks have a callback in a different position from 0#24344
let react-hooks/exhaustive-deps additionalHooks have a callback in a different position from 0#24344joeflateau wants to merge 3 commits intofacebook:mainfrom
Conversation
|
Comparing: df5d32f...2092c58 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
|
|
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. |
|
Would be great to have this merged... |
|
+1 |
|
+1 |
|
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 |
|
I have what I believe to be a very legit use case. My custom hook produces a queryKey and queryData with a "factory" similar to export const useSkippableQueryData = <TAppRoute extends AppRoute>(
_route: TAppRoute,
mainObjectName: ApiModelType,
queryDataFactory: () => SkippableQueryData<TAppRoute>,
dependencies: DependencyList,
): [QueryKey, SkippableQueryData<TAppRoute>] => {
const [queryKey, queryData] = useMemo<
[QueryKey, SkippableQueryData<TAppRoute>]
>(() => {
const queryData = queryDataFactory();
const queryKey: QueryKey = [
mainObjectName,
_route.method,
_route.path,
queryData,
];
return [queryKey, queryData];
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [...dependencies, _route, mainObjectName, queryDataFactory]);
return [queryKey, queryData];
};The important thing is I basically can't refactor this to put the callback in first position, due to how this is used : const [queryKey, queryData] = useSkippableQueryData(
contract.listCompanyExpense,
ApiModel.Expense,
() => ({
// This is typed, thanks to the contract stuff above
params: { companyId: myCompanyId }
}),
[myCompanyId]
)I deadly want my devs not to forget any dependency as it's critical in there; but in such a case it would require to declare |
|
please merge this pr 🙏 |
|
+1 please merge this |
|
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, still relevant in my opinion |
|
May I suggest a much simpler syntax for this option? (I always wondered why the original option is a regex instead of a string array...) This is how the (now unmaintained) plugin https://github.com/stoikio/eslint-plugin-react-hooks-static-deps does it |
|
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. |
|
Closing this pull request after a prolonged period of inactivity. If this issue is still present in the latest release, please ask for this pull request to be reopened. Thank you! |
|
this issue is still present AND relevant. Please fix it 🙏 |
|
Go biome. The project is maintained and the rule is still greatly configurable. |
Summary
This pull request allows Hooks specified in react-hooks/exhaustive-deps additionalHooks have a callback parameter in a position other than 0.
In my case, I have a hook where the callback is in position 1 rather than 0:
(simplified version, real version handles aborts/errors/etc but not relevant to this change)
I could refactor the hook and put
initialStateafter the callback/deps (at pos 2 rather than 0) but I feel like it reads out of order/more difficult to reason about.How did you test this change?
Added valid/invalid tests. Ran tests with
yarn test --watch ESLintRuleExhaustiveDeps. Existing and new tests pass.