react-use-previous-hook
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

react-use-previous-hook

Hook for using the previous value of props or state.

NPM JavaScript Style Guide

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

Readme

Keywords

none

Package Sidebar

Install

npm i react-use-previous-hook

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

4.95 kB

Total Files

9

Last publish

Collaborators

  • wsoeltz