use-effect-with-previous
TypeScript icon, indicating that this package has built-in type declarations

1.0.7 • Public • Published

use-effect-with-previous

A layer over useEffect that provides previous values of dependencies.

NPM

Install

npm install --save use-effect-with-previous

Usage

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.
    },
    [state, anotherState]
  );
}

License

MIT © juangabrieldev


This hook is created using create-react-hook.

Package Sidebar

Install

npm i use-effect-with-previous

Weekly Downloads

1,919

Version

1.0.7

License

MIT

Unpacked Size

10.2 kB

Total Files

17

Last publish

Collaborators

  • juangabrieldev