✨(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:
committed by
aleb_the_flash
parent
3eef4765df
commit
b248395cd6
9
src/frontend/src/hooks/usePrevious.ts
Normal file
9
src/frontend/src/hooks/usePrevious.ts
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user