Skip to content

Rename useCallbackOncePerRender to useCallbackOnce #542

Closed

Description

@hyesungoh

useCallbackOncePerRender runs the callback once until deps change, not once per render, so the name suggests the opposite of what it does.

  • Add useCallbackOnce with the same signature and behavior, and mark useCallbackOncePerRender as deprecated.
  • Rewrite the JSDoc description to say the callback runs once until deps change, and fix @param {() => void} callback, which also accepts functions with arguments.
  • Fix the second example. The returned function keeps the same reference, so useEffect(() => trackUserVisit(), [trackUserVisit]) does not run again when userId changes. Add userId to the dependency list.

Update docs and tests.

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

Metadata

Metadata

Assignees

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