Skip to content

Commit

Permalink
fix: make useElmish hook work correctly in React strict mode (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
atheck committed Sep 7, 2022
1 parent c3c2b66 commit 0e0e855
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/useElmish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,12 @@ function useElmish<TProps, TModel, TMessage extends MessageBase> ({ name, props,
const propsRef = useRef(props);
const isMountedRef = useRef(true);

useEffect(() => () => {
isMountedRef.current = false;
useEffect(() => {
isMountedRef.current = true;

return () => {
isMountedRef.current = false;
};
}, []);

let initializedModel = model;
Expand Down

0 comments on commit 0e0e855

Please sign in to comment.