Use as the equalityFn argument to Redux useSelector when the selected value is an Object.
To install:
npm install @karmaniverous/block-refresh
To import:
import { blockRefresh } from '@karmaniverous/block-refresh`;
See tests for examples of usage!
- blockRefresh([a], [b], [options]) ⇒
boolean
Use as the equalityFn argument to Redux useSelector() when the selected value is an Object. https://react-redux.js.org/api/hooks#useselector
- EqalityFn ⇒
boolean
Return true if the two inputs should be considered equal.
Use as the equalityFn argument to Redux useSelector() when the selected value is an Object. https://react-redux.js.org/api/hooks#useselector
Kind: global function
Returns: boolean
- If true, component will not refresh.
Param | Type | Description |
---|---|---|
[a] | any |
Current useSelector result. |
[b] | any |
Last useSelector result. |
[options] | Object |
Options object. |
[options.log] | string |
If defined, function will console log a & b values with log value as label when refresh is blocked. |
[options.path] | string |
A Lodash-style path into the selected object. If defined, the equality test will be restricted to that path. Useful when an object has an update timestamp. |
[options.predicate] | EqalityFn |
Returns true if refresh should be blocked. If predicate is populated, path & refreshUndefined are ignored. |
[options.refreshUndefined] | boolean |
If true, component will refresh when both comparison values are undefined. |
Example
// Passed as a function, it will block component refresh if the current &
// previous values are defined & pass _.isEqual.
const obj = useSelector((state) => state.slice.obj, blockRefresh);
Example
// Deploy as an anonymous function to set options.
const obj = useSelector(
(state) => state.slice.obj,
(a, b) => blockRefresh(a, b, options)
);
Return true if the two inputs should be considered equal.
Kind: global typedef
Param | Type |
---|---|
[a] | any |
[b] | any |
See more great templates and other tools on my GitHub Profile!