From 49d1045e419a9bd74ed900988756505f556ce2f3 Mon Sep 17 00:00:00 2001 From: candymask0712 Date: Wed, 26 Feb 2025 23:47:40 +0900 Subject: [PATCH] fix: Modifying the useFirstMountState code for proper functioning in React 19 strict mode --- src/useFirstMountState.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/useFirstMountState.ts b/src/useFirstMountState.ts index cf210622a2..9c8121f5e5 100644 --- a/src/useFirstMountState.ts +++ b/src/useFirstMountState.ts @@ -1,13 +1,14 @@ -import { useRef } from 'react'; +import { useEffect, useRef } from 'react'; export function useFirstMountState(): boolean { const isFirst = useRef(true); - if (isFirst.current) { + useEffect(() => { isFirst.current = false; - - return true; - } + return () => { + isFirst.current = true; + }; + }, []); return isFirst.current; }