Skip to content

v7.1.0-alpha.5

Pre-release
Pre-release
Compare
Choose a tag to compare
@markerikson markerikson released this 20 May 00:31

We're still making changes to our hooks APIs, but I'm hopeful that we're getting close to having the behavior nailed down.

This release makes three specific changes to useSelector:

  • The deps array has been removed. If you want to ensure the same selector function reference is used, you should memoize it yourself.
  • The default equality check used to determine if a re-render is needed is now a strict === check, instead of a shallow equality check.
  • useSelector now accepts a comparison function as an optional second argument, similar to how React.memo() works conceptually. You may pass your own comparison function to customize how useSelector determines if a re-render is necessary.

In addition, we now export our internal shallowEqual utility function. If you want to return to the prior equality behavior, you may pass that as the equality comparison function:

import { shallowEqual, useSelector } from "react-redux"

// later
const selectedData = useSelector(mySelector, shallowEqual)

The optional comparison function also enables using something like Lodash's _.isEqual() or Immutable.js's comparison capabilities.

Changes