2.0.8 • Published 2 years ago

@washingtonpost/red-react-lib v2.0.8

Weekly downloads
36
License
-
Repository
-
Last release
2 years ago

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

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

Functions

hooks

usePrevious(value)

usePrevious Hook

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

Kind: global function

ParamTypeDescription
value*The value to save

Example

const [state, setState] = React.useState()
const prev = usePrevious(state)

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

ParamTypeDescription
promisePromiseThe promise that would be wrapped
depsArray.<any>extra deps used to re-create the callback
delayMSnumberThe delay in ms to switch the loading state to true

Example

const [callback, result, loading, err] = usePromiseCallback(Promise.resolve, [], 500)

usePromise(promise, deps, delayMS)

usePromise Hook

Wrapped usePromiseCallback.

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

Useful to fetch page data.

Kind: global function

ParamTypeDescription
promisePromiseThe promise that would be wrapped
depsArray.<any>deps to call the function with
delayMSnumberThe delay in ms to switch the loading state to true

Example

const [callback, result, loading, err] = usePromise(Promise.resolve, ["hello"], 500)
2.0.8

2 years ago

2.0.7

2 years ago

2.0.6

3 years ago

2.0.5

4 years ago

2.0.4

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago