forked from anIcedAntFA/recursive-docs-reactjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ngockhoi96
committed
May 26, 2023
1 parent
1fa28d9
commit 8556750
Showing
7 changed files
with
57 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import Tree from './components/Tree'; | ||
import { getTreeData } from './utils/getTreeData'; | ||
import { useNodeStore } from './store'; | ||
|
||
function App() { | ||
return <Tree treeData={getTreeData()} />; | ||
const { state } = useNodeStore(); | ||
|
||
return <Tree treeData={state.nodeList} />; | ||
} | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
export const nodeActionVariant = { | ||
addNode: 'addNode', | ||
getNode: 'getNode', | ||
getNodeList: 'getNodeList', | ||
updateNode: 'updateNode', | ||
toggleHasChildren: 'toggleHasChildren', | ||
removeNode: 'removeNode', | ||
} as const; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
import { useEffect, useReducer } from 'react'; | ||
import { useMemo, useReducer } from 'react'; | ||
|
||
import NodeContext from './context.store'; | ||
import nodeReducer, { initialNodeState } from './reducer.store'; | ||
import { TNodeProviderProps } from './type.store'; | ||
|
||
function NodeProvider({ children }: TNodeProviderProps) { | ||
const [state, dispatch] = useReducer(nodeReducer, initialNodeState); | ||
const [state, dispatch] = useReducer(nodeReducer, initialNodeState()); | ||
|
||
return ( | ||
<NodeContext.Provider value={{ state, dispatch }}> | ||
{children} | ||
</NodeContext.Provider> | ||
); | ||
const value = useMemo(() => { | ||
console.log(state); | ||
return { state, dispatch }; | ||
}, [state]); | ||
|
||
return <NodeContext.Provider value={value}>{children}</NodeContext.Provider>; | ||
} | ||
|
||
export default NodeProvider; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters