use-effect-with-previous
Version:
A layer over useEffect that provides previous values of dependencies.
38 lines (25 loc) • 836 B
Markdown
//img.shields.io/npm/v/use-effect-with-previous.svg)](https://www.npmjs.com/package/use-effect-with-previous)
```bash
npm install --save use-effect-with-previous
```
```js
import useEffectWithPrevious from 'use-effect-with-previous'
const Example = () => {
const [ state, setState ] = useState(1);
const [ anotherState, setAnotherState ] = useState(2);
useEffectWithPrevious(
([ previousState, previousAnotherState ]) => {
// Compare previous and current state.
},
[ ]
);
}
```
MIT © [juangabrieldev](https://github.com/juangabrieldev)
---
This hook is created using [create-react-hook](https://github.com/hermanya/create-react-hook).
> A layer over useEffect that provides previous values of dependencies.
[![NPM](https: