Create New Item
Item Type
File
Folder
Item Name
Search file in folder and subfolders...
Are you sure want to rename?
optometrists
/
cache
/
cache
/
cache
/
.wp-cli
/
wp-content
/
plugins
/
woocommerce
/
packages
/
woocommerce-blocks
/
assets
/
js
/
base
/
hooks
:
use-previous.ts
Advanced Search
Upload
New Item
Settings
Back
Back Up
Advanced Editor
Save
/** * External dependencies */ import { useRef, useEffect } from 'react'; interface Validation< T > { ( value: T, previousValue: T | undefined ): boolean; } /** * Use Previous based on https://usehooks.com/usePrevious/. * * @param {*} value * @param {Function} [validation] Function that needs to validate for the value * to be updated. */ export function usePrevious< T >( value: T, validation?: Validation< T > ): T | undefined { const ref = useRef< T >(); useEffect( () => { if ( ref.current !== value && ( ! validation || validation( value, ref.current ) ) ) { ref.current = value; } }, [ value, validation ] ); return ref.current; }