Skip to content
This repository was archived by the owner on Dec 18, 2025. It is now read-only.
This repository was archived by the owner on Dec 18, 2025. It is now read-only.

[Question] Using callback and preservedCallback inside useRefEffect #519

Description

@jin-Pro

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions