Skip to content

Latest commit

 

History

History
26 lines (19 loc) · 507 Bytes

usePrevious.md

File metadata and controls

26 lines (19 loc) · 507 Bytes

usePrevious

React state hook that returns the previous state as described in the React hooks FAQ.

Usage

import {usePrevious} from 'react-use';

const Demo = () => {
  const [count, setCount] = React.useState(0);
  const prevCount = usePrevious(count);

  return (
    <p>
      Now: {count}, before: {prevCount}
    </p>
  );
};

Reference

const prevState = usePrevious = <T>(state: T): T;