Skip to content

Commit

Permalink
fix: fix useMountedState in hooks.ts not correct init leavingRef …
Browse files Browse the repository at this point in the history
…in StrictMode. (#292)

* fix: fix `useMountedState` in `hooks.ts` not correct init leavingRef value in React 18 StrictMode

(cherry picked from commit e18d76c)

* docs[hooks]: Add comment with reference to PR 292

---------

Co-authored-by: Aex <adaex.yang@bytedance.com>
  • Loading branch information
molinla and adaex authored Nov 21, 2024
1 parent a717540 commit af2bf5d
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/arcodesign/components/_helpers/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,13 @@ export function useMountedState<S>(initialState: S | (() => S)) {
}
setState(value);
}, []);
useEffect(
() => () => {
useEffect(() => {
// see: https://github.com/arco-design/arco-design-mobile/pull/292
leavingRef.current = false;
return () => {
leavingRef.current = true;
},
[],
);
};
}, []);
const result: [S, typeof setState] = [state, setValidState];
return result;
}
Expand Down

0 comments on commit af2bf5d

Please sign in to comment.