File tree Expand file tree Collapse file tree 1 file changed +5
-12
lines changed Expand file tree Collapse file tree 1 file changed +5
-12
lines changed Original file line number Diff line number Diff line change 11import { useEffect , useState } from "react" ;
22import { TreeConfig , TreeState , createTree } from "@headless-tree/core" ;
33
4- let mounted = false ;
5-
64export const useTree = < T , > ( config : TreeConfig < T > ) => {
75 const [ tree ] = useState ( ( ) => ( { current : createTree ( config ) } ) ) ;
86 const [ state , setState ] = useState < Partial < TreeState < T > > > ( ( ) =>
97 tree . current . getState ( ) ,
108 ) ;
119
1210 useEffect ( ( ) => {
13- // (tree.current as any).setMounted(true);
11+ ( tree . current as any ) . setMounted ( true ) ;
1412 tree . current . rebuildTree ( ) ;
15- setInterval ( ( ) => {
16- mounted = ! mounted ;
17- ( tree . current as any ) . setMounted ( mounted ) ;
18- console . log ( { mounted } ) ;
19- } , 3000 ) ;
20- // return () => {
21- // // eslint-disable-next-line react-hooks/exhaustive-deps
22- // (tree.current as any).setMounted(false);
23- // };
13+ return ( ) => {
14+ // eslint-disable-next-line react-hooks/exhaustive-deps
15+ ( tree . current as any ) . setMounted ( false ) ;
16+ } ;
2417 } , [ tree ] ) ;
2518
2619 tree . current . setConfig ( ( prev ) => ( {
You can’t perform that action at this time.
0 commit comments