Skip to content

Rename equality options to equalityFn #540

Description

@hyesungoh

The comparison option has three names: compare in usePrevious, equalityFn in useControlledState, and areValuesEqual in usePreservedReference. All three have the same type, (a, b) => boolean.

  • Rename the parameter to equalityFn in usePrevious and usePreservedReference. Both are positional, so only types and docs change.
  • Change the default in usePrevious from === to Object.is, which useControlledState and React already use. Only NaN and -0 behave differently.
  • Keep the deep comparison default in usePreservedReference, because keeping the reference of deeply equal values is what the hook is for.

Update types, docs, and tests.

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