1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 04:46:40 +07:00

resetting node on unmount

This commit is contained in:
Fedor Katurov 2021-03-31 12:25:31 +07:00
parent 5b507bc736
commit 1db5c64d06

View file

@ -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]);
};