one-hook
Size
0.16 kb
View source

usePrevious

Returns the previous value.

Installation

npm install @1hook/use-previous

Usage

import {  } from '@1hook/use-previous'

Get the previous value:

const  = ()

Custom isEqual function to compare the previous and current values.

import { isEqual } from 'lodash'

const previous = usePrevious(value, { isEqual })

API Reference

UsePreviousOptions

The options for the usePrevious hook.

PropTypeDefault
isEqual?
((prev: T | undefined, next: T) => boolean)
Object.is

On this page