Hooks

usePrevious

Publisher

cermuel

50 hooks published

More from this publisher

usePrevious

Retain the previous value.

usePrevious.tsx
import { useState } from "react";import { usePrevious } from "@cermuel/hooks/react";export function usePreviousExample() {  const [count, setCount] = useState(0);  const previous = usePrevious(count);  return <button type="button" onClick={() => setCount(count + 1)}>Previous: {previous ?? 0}</button>;}

Props

Param
Type
Default Value
value
T

Returns

T | undefined