(frontend) introduce usePrevious utility hook

Add new usePrevious utility hook to track previous values in functional
components. Enables comparing current and previous prop/state values across
renders for improved state management.
This commit is contained in:
lebaudantoine
2025-03-05 19:03:06 +01:00
committed by aleb_the_flash
parent 3eef4765df
commit b248395cd6

View File

@@ -0,0 +1,9 @@
import { useEffect, useRef } from 'react'
export const usePrevious = <T>(value: T): T | undefined => {
const ref = useRef<T>()
useEffect(() => {
ref.current = value
}, [value])
return ref.current
}