Skip to content
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

chore: avoid react linting errors (attempt #2) #85

Merged

Conversation

pkerschbaum
Copy link
Contributor

Prerequisites checklist

What is the purpose of this pull request?

Attempt #2 (after #83) to unblock #70.
By avoiding the 2 linting errors already present in the codebase.

What changes did you make? (Give an overview)

This time, I did not introduce any behavior changes.
I just replaced useCallback by useMemo because then the warning React Hook useCallback received a function whose dependencies are unknown vanishes.

  • chore: disable warning for useEffect for code path on mount
  • chore: avoid warning by replacing useCallback by useMemo

Related Issues

Is there anything you'd like reviewers to focus on?

Copy link

netlify bot commented Mar 1, 2025

Deploy Preview for eslint-code-explorer ready!

Name Link
🔨 Latest commit 45eef42
🔍 Latest deploy log https://app.netlify.com/sites/eslint-code-explorer/deploys/67c30ded596edb0008057ea2
😎 Deploy Preview https://deploy-preview-85--eslint-code-explorer.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@pkerschbaum
Copy link
Contributor Author

I tested that it does not cause issues when typing quickly into the editor (was the problem with #83).

Copy link
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks.

@nzakas nzakas merged commit a7b2a22 into eslint:main Mar 3, 2025
7 checks passed
() =>
debounce((value: string) => {
onChange?.(value);
}, 400),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


const debouncedOnChange = useMemo(
		() =>
			debounce((value: string) => {
				onChange?.(value);
			}, 400),
		[onChange],
	);
	

How does useMemo help in this case? We are returning a function, not a value. useCallback is preferred when using a function. In this case, if we use useMemo, it wouldn't have any impact, right? Is my understanding correct, or am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functionally, it is equivalent, see also https://react.dev/reference/react/useCallback#how-is-usecallback-related-to-usememo
But for whatever reason, the react eslint plugin would warn when using useCallback:

React Hook useCallback received a function whose dependencies are unknown. Pass an inline function instead. eslint(react-hooks/exhaustive-deps)

That error vanishes with useMemo.

@pkerschbaum pkerschbaum deleted the chore/avoid-react-linting-errors-attempt-2 branch March 3, 2025 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants