react icon indicating copy to clipboard operation
react copied to clipboard

fix(eslint-plugin): ExhaustiveDeps: Auto fixing should add a dependency array to `useMemo` and `useCallback`

Open AhmedBaset opened this issue 1 year ago • 4 comments

Summary

useMemo and useCallback accept two required parameters. Currently, when including unstable reference in Effect/Memo/Callback dependency array, the eslint plugin will suggest to wrap the unstable reference with useCallback/useMemo

The {reference} function makes the dependencies of useCallback Hook (at line 70) change on every render. To fix this, wrap the definition of 'checkItem' in its own useCallback() Hook.eslintreact-hooks/exhaustive-deps

When accpting the suggestion, It will wrap it with a useMemo/useCallback without a dependency array

const func = useCallback(() => {})

At this point, TypeScript will complain since the second argument of useMemo and useCallback is required.

This PR adds an empty array to the auto-fixing to be like

const func = useCallback(() => {}, [])

Now, the TS error will be fixed. If the function depends on references, the plugin will suggest to add the missing dependencies.

AhmedBaset avatar Mar 31 '24 06:03 AhmedBaset

The size diff is too large to display in a single comment. The GitHub action for this pull request contains an artifact called 'sizebot-message.md' with the full message.

Generated by :no_entry_sign: dangerJS against ce5bf45ccde4fa6a76d24cba3ec7b2d9e1a0045d

react-sizebot avatar Mar 31 '24 06:03 react-sizebot

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.

github-actions[bot] avatar Jun 29 '24 07:06 github-actions[bot]

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-compiler-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 27, 2024 10:53am

vercel[bot] avatar Jun 29 '24 08:06 vercel[bot]

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.

github-actions[bot] avatar Sep 27 '24 09:09 github-actions[bot]

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.

github-actions[bot] avatar Dec 26 '24 11:12 github-actions[bot]

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!

github-actions[bot] avatar Jan 02 '25 11:01 github-actions[bot]