1.0.1 • Published 4 years ago

react-use-previous-hook v1.0.1

Weekly downloads
21
License
MIT
Repository
github
Last release
4 years ago

react-use-previous-hook

Hook for using the previous value of props or state.

NPM JavaScript Style Guide

View demo ↗

Install

npm install --save react-use-previous-hook

Usage

import React, {useState} from 'react'
import usePrevious from 'react-use-previous-hook'

const App = () => {
  const [count, setCount] = useState<number>(0);

  const previousCount = usePrevious(count);

  return (
    <div>
      <h1>Current count: {count}</h1>
      <h1>Previous count: {previousCount}</h1>
      <button onClick={() => setCount(count - 1)}>Count -</button>
      <button onClick={() => setCount(count + 1)}>Count +</button>
    </div>
  );
}

export default App

License

MIT © wsoeltz