From b248395cd68d7b745ccac49626ee5cf9a941bdcb Mon Sep 17 00:00:00 2001 From: lebaudantoine Date: Wed, 5 Mar 2025 19:03:06 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8(frontend)=20introduce=20usePrevious?= =?UTF-8?q?=20utility=20hook?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- src/frontend/src/hooks/usePrevious.ts | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/frontend/src/hooks/usePrevious.ts diff --git a/src/frontend/src/hooks/usePrevious.ts b/src/frontend/src/hooks/usePrevious.ts new file mode 100644 index 00000000..ff79f7e9 --- /dev/null +++ b/src/frontend/src/hooks/usePrevious.ts @@ -0,0 +1,9 @@ +import { useEffect, useRef } from 'react' + +export const usePrevious = (value: T): T | undefined => { + const ref = useRef() + useEffect(() => { + ref.current = value + }, [value]) + return ref.current +}