From 54d80967e2dc53205d02369273bde94040f0276d Mon Sep 17 00:00:00 2001 From: Enger Then Date: Fri, 28 Oct 2022 11:40:31 -0400 Subject: [PATCH] chore(docs): added custom equalityFn example --- docs/api/hooks.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/api/hooks.md b/docs/api/hooks.md index db8d20840..337354ac2 100644 --- a/docs/api/hooks.md +++ b/docs/api/hooks.md @@ -100,6 +100,18 @@ import { shallowEqual, useSelector } from 'react-redux' const selectedData = useSelector(selectorReturningObject, shallowEqual) ``` +- Use a custom equality function as the `equalityFn` argument to `useSelector()`, like: + +```js +import { useSelector } from 'react-redux' + +// equality function +const customEqual = (oldValue, newValue) => oldValue === newValue + +// later +const selectedData = useSelector(selectorReturningObject, customEqual) +``` + The optional comparison function also enables using something like Lodash's `_.isEqual()` or Immutable.js's comparison capabilities. ### `useSelector` Examples