Hooks
usePrevious()

usePrevious()

Track the previous value of a variable.

Usage

import { useState } from 'react';
import { usePrevious } from '@norr/hooks';
 
const Component = () => {
  const [count, setCount] = useState(0);
  const previousCount = usePrevious(count);
 
  return (
    <>
      <span>
        Now: {count}, before: {previousCount}
      </span>
      <button type="button" onClick={() => setCount(count + 1)}>
        Increment
      </button>
    </>
  );
};