import { action , observable } from 'mobx' ; import { useContext } from 'react' ; import { useObservableRef } from '../useObservableRef' ; import { FolderExplorerContext , IFolderExplorerContext } from './FolderExplorerContext' ; export function useFolderExplorer ( root ) { const context = useContext ( FolderExplorerContext ) ; const state = useObservableRef < IFolderExplorerContext > ( ( ) => ( { root , path : [ ] , fullPath : [ root ] , folder : root , open ( path , folder ) { this . path = path . slice ( ) ; this . fullPath = [ ... path , folder ] ; this . folder = folder ; } , } ) , { root : observable , path : observable , fullPath : observable , folder : observable , open : action . bound , } , false ) ; return context || state ; }