An open API service indexing awesome lists of open source software.

https://github.com/karmaniverous/block-refresh

Use as the equalityFn argument to Redux useSelector() when the selected value is an Object.
https://github.com/karmaniverous/block-refresh

react redux useselector

Last synced: 9 months ago
JSON representation

Use as the equalityFn argument to Redux useSelector() when the selected value is an Object.

Awesome Lists containing this project

README

          

# block-refresh

Use as the equalityFn argument to Redux
[useSelector](https://react-redux.js.org/api/hooks#useselector) when the
selected value is an Object.

To install:

```bash
npm install @karmaniverous/block-refresh
```

To import:

```js
import { blockRefresh } from '@karmaniverous/block-refresh`;
```

See
[tests](https://github.com/karmaniverous/block-refresh/blob/main/lib/blockRefresh/blockRefresh.test.js)
for examples of usage!

# API Documentation

## Functions



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



## Typedefs



EqalityFnboolean


Return true if the two inputs should be considered equal.



## 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

**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](#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**
```js
// 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**
```js
// Deploy as an anonymous function to set options.
const obj = useSelector(
(state) => state.slice.obj,
(a, b) => blockRefresh(a, b, options)
);
```

## EqalityFn ⇒ boolean
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](https://github.com/karmaniverous)!