Search
K
Comment on page

usePrevious

Track previous versions of values.
Source code is hosted on GitHub
yarn
npm
yarn add @corets/use-previous
npm install --save @corets/use-previous

usePrevious()

Get the previous version of a value:
import React, { useState } from "react"
import { usePrevious } from "@corets/use-previous"
const Example = () => {
const [count, setCount] = useState(0)
const previousCount = usePrevious(count)
return (
<div>
<div>count: {count}</div>
<div>previous count: {previousCount}</div>
</div>
)
}