usePrevious

Track previous versions of values.

Source code is hosted on GitHub

yarn add @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>
  )
}

Last updated