From 1db5c64d06c3adfc6c31a160fbc69de189f13a47 Mon Sep 17 00:00:00 2001 From: Fedor Katurov Date: Wed, 31 Mar 2021 12:25:31 +0700 Subject: [PATCH] resetting node on unmount --- src/utils/hooks/node/useLoadNode.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/utils/hooks/node/useLoadNode.ts b/src/utils/hooks/node/useLoadNode.ts index 6d21392a..600fa0a2 100644 --- a/src/utils/hooks/node/useLoadNode.ts +++ b/src/utils/hooks/node/useLoadNode.ts @@ -1,6 +1,7 @@ import { useEffect } from 'react'; -import { nodeGotoNode } from '~/redux/node/actions'; +import { nodeGotoNode, nodeSetCurrent } from '~/redux/node/actions'; import { useDispatch } from 'react-redux'; +import { EMPTY_NODE } from '~/redux/node/constants'; // useLoadNode loads node on id change export const useLoadNode = (id: any, isLoading: boolean) => { @@ -9,5 +10,9 @@ export const useLoadNode = (id: any, isLoading: boolean) => { useEffect(() => { if (isLoading) return; dispatch(nodeGotoNode(parseInt(id, 10), undefined)); + + return () => { + dispatch(nodeSetCurrent(EMPTY_NODE)); + }; }, [dispatch, id]); };