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

[Question] Using callback and preservedCallback inside useRefEffect #519

Open
jin-Pro opened this issue Mar 25, 2025 · 0 comments
Open

[Question] Using callback and preservedCallback inside useRefEffect #519

jin-Pro opened this issue Mar 25, 2025 · 0 comments

Comments

@jin-Pro
Copy link

jin-Pro commented Mar 25, 2025

const preservedCallback = usePreservedCallback(callback);

As you can see from the above code, you created a 'preservedCallback' using 'usePreservedCallback' to keep a reference to the 'callback'.

[preservedCallback, ...deps]

When wrapping 'useCallback' to maintain a reference to 'effect', the return value of 'useRefEffect'. you use 'preservedCallback' created in 15L as a dependency.

const cleanup = callback(element);

But, the function used inside 'effect', which is the return value, uses 'callback', not 'preservedCallback'.

Is this intended behavior?

[ 1 ]

If you don't want to affect the 'effect' reference change due to the reference change of 'callback', use 'preservedCallback' in deps, but the actual operation is to use callback.

I'm wondering if I need to use 'preservedCallback' when using 'eslint-disable'.

[ 2 ]

To avoid confusion in code

const cleanup = callback(element);

I'm thinking that maybe I should use 'preservedCallback' instead of 'callback' in the above code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant