Socket
Socket
Sign inDemoInstall

react-use-previous-hook

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-use-previous-hook

Hook for using the previous value of props or state.


Version published
Maintainers
1
Install size
5.94 kB
Created

Readme

Source

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

FAQs

Last updated on 02 Aug 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc