diff --git a/src/useElmish.ts b/src/useElmish.ts index 7c9f443..b6e4cf6 100644 --- a/src/useElmish.ts +++ b/src/useElmish.ts @@ -61,9 +61,14 @@ function useElmish ({ name, props, let currentModel: Partial = {}; const [model, setModel] = useState>(null); - let initializedModel = model; - const propsRef = useRef(props); + const isMountedRef = useRef(true); + + useEffect(() => () => { + isMountedRef.current = false; + }, []); + + let initializedModel = model; if (propsRef.current !== props) { propsRef.current = props; @@ -106,7 +111,7 @@ function useElmish ({ name, props, } reentered = false; - if (modified) { + if (isMountedRef.current && modified) { setModel(prevModel => { const updatedModel = { ...prevModel as TModel, ...currentModel };