# @washingtonpost/red-react-lib

> This lib points to be a shared codebase for the different projects inside the WP.

Latest version **2.0.8** (published 2022-10-21) · 0 weekly downloads

## Install

```sh
npm install @washingtonpost/red-react-lib
pnpm add @washingtonpost/red-react-lib
yarn add @washingtonpost/red-react-lib
bun add @washingtonpost/red-react-lib
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.8 |
| Published | 2022-10-21 |
| First published | 2020-07-22 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 265.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | bantupallik, kt-prry, jesse.post.washpo, threeteaspoons, emilycsabens, shelby.kiefner, ortaeg, ggomez25, luciovilla, tam.steph, agillespie, weathergrrl1103, ani512, vonoehsene, emmakumer, aggyjlee, lavanderoi, amyerz, emily.eng, lmelgar, sadbumblebee, sotojl, janicekchen, jamelhendricks, ryanpicou, crunchwrap78, welchk, val-l-hosler, tylrfishr, nick.mourtoupalas, benjaki, battand, jon.rosado, jacknugent27, walliby, asamireissa, courth, nguyenk2, mahig, jchaskell, lorenzog, cohenl, carlyle, ln-washpost, chriszs, stericson, alecredman, talpert022, gengel, haileyhaymond, thomas-corrado, rasengawd, smurthy221, tuckabelle, sharmas2, aliaelkattan, nauticaharvin, aadittambe, rachelanneorr, natalievineberg, krbrooks, katty-huertas, mariaalconadabrooks, juniorh28, atomictangerine, emlorraine, helmsc, tritico, pranavganore, danacasidy, terrywp, ksemanur8, alejandro.resendiz.wp, rwestwapo, thomas-thepost, dreyvitser, devinsharpe, mvonesh, chelseaconrad, arnolda-wp, hermionewy, wp-aberg, sheamus-hei, haysstephanie, broadwaterne, andrevinc, kat-alo, daniellersaul, unconstruct, stevefuenteswp, bokanm, rekha26, marcnahed, amiemunoz, chloelangston, nmargoliswp, martinezy, seanwapo, ducroquet, abidis, jakekara, jtotoole, mjperales, arturgalocha, ebgranger, christian-wp, ramyalamati, adamsrobw, obentham, luke.connors, wrneff, mcdoh, floresa, taliatrackim, mirzaa, lennybronner, bitsoglass, it_procurement, erikreyna, davidchaiwapo, maddoxnelson, juliebacon, stephanie.clark, bernertj, simongle, jasonvuong, andrew.frye, jkoo87, kankelcr, erikawhiteshoes, gregoryauld2014, uncompiled, jbrown4, st421, scarothers, khan.salauddin, rowhawn, subs-npm-builder, littlemsbozzi, nealhumphreywapo, gabrielflorit, ashlynstill, ptnielsen, leslie-s, courtney-kan, kevin.schaul, jakecrump, macallah, jmuyskens, sbanks, madisonwalls, brianaa, dsantamarina, artmsilva, robpc, ashtol, sberhanu, joannejoolee, jjalcantara, alyssa.fowers, brmayes, joemfox, reubenfb, calcantara, meggonagul, adrianblanco, chiquiesteban, iuraizee, bdgross, ulmonica, bmferrill, dankeating, emamd, timmeko, kevinuhrmacher, shellytan, harrystevens, chrisrukan, allisonnmann, aaronsteckelberg, shruthagandla, braforda, hannahmahon, adityajain15, linorabolini, liue, anthonyjpesce, 1313davidlee, kutyadog, kate.rabinowitz, fontc, cecepascual, vsingarayar, aramzs, ruxk, nader_heidari, thompsond3, judesfernando, mlemieuxwp, tylerremmel, dwuanjune, cashack, clareramirez, rcoughlin, tmac0201, joemoore-post, hs4man21, kamari, ealvarez79, hdormido, lobenichou, sgpotts, yutaochen, nwalker_wp, apbest, briannaschroer, shikha-sub, naema, chloemeister, julia.ledur, solomonsscott, betchavarria, eewright, mariaaguilar, nickkirkpatrick, trann_wapo, jlsoto, tobefrankhj, tierneyl, essiekim, styonsk, sergio.pecanha, meganwalter, alyssabartuch, alexisbarnes, cullenrombach, foggva, dmoriarty6, mokhtar.ali, dpham5, klimenkovd, davisshaver, aaronbrezel, moodypaige.e, caveat, kastningj, freedmand, washpostdavis |

## Links

- npm: https://www.npmjs.com/package/@washingtonpost/red-react-lib
- npm.io page: https://npm.io/package/@washingtonpost/red-react-lib

## Recent versions

- 2.0.8 (latest) — 2022-10-21
- 2.0.7 — 2022-09-14
- 2.0.6 — 2020-12-23
- 2.0.5 — 2020-11-19
- 2.0.4 — 2020-11-19
- 2.0.3 — 2020-11-18
- 2.0.2 — 2020-11-18
- 2.0.1 — 2020-09-28
- 2.0.0 — 2020-09-28
- 1.0.2 — 2020-08-10
- 1.0.1 — 2020-07-22
- 1.0.0 — 2020-07-22

## README

# red-react-lib

This lib points to be a shared codebase for the different projects inside the WP.

For the time being we are using it as a [git
subtree](https://www.atlassian.com/blog/git/alternatives-to-git-submodule-git-subtree)

## Updating this lib

In order to update/commit an update, the code needs to be built before pushing.

### To build the project run

```
yarn install
yarn build
```

## Modules

<dl>
<dt><a href="#module_hooks">hooks</a></dt>
<dd></dd>
</dl>

## Functions

<dl>
<dt><a href="#usePrevious">usePrevious(value)</a></dt>
<dd><p>usePrevious Hook</p>
<p>Got from <a href="https://usehooks.com/usePrevious/">https://usehooks.com/usePrevious/</a>
It saves the previous value of props or state</p>
</dd>
<dt><a href="#usePromiseCallback">usePromiseCallback(promise, deps, delayMS)</a></dt>
<dd><p>usePromiseCallback Hook</p>
<p>Hook dedicated to offer a sync way of accessing a promise state.</p>
<p>Keeps the last result until new results are loaded, to avoid UI flashes.</p>
<p>Supports a delayMS param to customise the loading threshold, to avoid UI flashes.</p>
<p>Only processes the last promise call.</p>
</dd>
<dt><a href="#usePromise">usePromise(promise, deps, delayMS)</a></dt>
<dd><p>usePromise Hook</p>
<p>Wrapped <a href="module:hooks.usePromiseCallback">usePromiseCallback</a>.</p>
<p>It gets triggered on init and every time the args change by default.</p>
<p>Useful to fetch page data.</p>
</dd>
</dl>

<a name="module_hooks"></a>

## hooks
<a name="usePrevious"></a>

## usePrevious(value)
usePrevious Hook

Got from https://usehooks.com/usePrevious/
It saves the previous value of props or state

**Kind**: global function  

| Param | Type | Description |
| --- | --- | --- |
| value | <code>\*</code> | The value to save |

**Example**  
```js
const [state, setState] = React.useState()
const prev = usePrevious(state)
```
<a name="usePromiseCallback"></a>

## usePromiseCallback(promise, deps, delayMS)
usePromiseCallback Hook

Hook dedicated to offer a sync way of accessing a promise state.

Keeps the last result until new results are loaded, to avoid UI flashes.

Supports a delayMS param to customise the loading threshold, to avoid UI flashes.

Only processes the last promise call.

**Kind**: global function  

| Param | Type | Description |
| --- | --- | --- |
| promise | <code>Promise</code> | The promise that would be wrapped |
| deps | <code>Array.&lt;any&gt;</code> | extra deps used to re-create the callback |
| delayMS | <code>number</code> | The delay in ms to switch the loading state to true |

**Example**  
```js
const [callback, result, loading, err] = usePromiseCallback(Promise.resolve, [], 500)
```
<a name="usePromise"></a>

## usePromise(promise, deps, delayMS)
usePromise Hook

Wrapped [usePromiseCallback](module:hooks.usePromiseCallback).

It gets triggered on init and every time the args change by default.

Useful to fetch page data.

**Kind**: global function  

| Param | Type | Description |
| --- | --- | --- |
| promise | <code>Promise</code> | The promise that would be wrapped |
| deps | <code>Array.&lt;any&gt;</code> | deps to call the function with |
| delayMS | <code>number</code> | The delay in ms to switch the loading state to true |

**Example**  
```js
const [callback, result, loading, err] = usePromise(Promise.resolve, ["hello"], 500)
```

---
_Source: https://npm.io/package/@washingtonpost/red-react-lib · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
