packageDocumentation module import { useCallback , useEffect , useMemo , useState } from "react" ; import { useDisposable } from "@itwin/core-react" ; import { TreeDataProvider } from "../TreeDataProvider" ; import { TreeEventHandler , TreeEventHandlerParams } from "./TreeEventHandler" ; import { TreeModel } from "./TreeModel" ; import { TreeModelSource } from "./TreeModelSource" ; import { PagedTreeNodeLoader , TreeNodeLoader } from "./TreeNodeLoader" ; public export function useTreeModel ( modelSource ) { const [ model , setModel ] = useState ( modelSource . getModel ( ) ) ; useEffect ( ( ) => { const onModelChanged = ( ) => { setModel ( modelSource . getModel ( ) ) ; } ; onModelChanged ( ) ; return modelSource . onModelChanged . addListener ( onModelChanged ) ; } , [ modelSource ] ) ; return model ; } public export function useTreeNodeLoader < TDataProvider extends TreeDataProvider > ( dataProvider , modelSource ) { const createLoader = useCallback ( ( ) => new TreeNodeLoader ( dataProvider , modelSource ) , [ dataProvider , modelSource ] ) ; return useDisposable ( createLoader ) ; } public export function usePagedTreeNodeLoader < TDataProvider extends TreeDataProvider > ( dataProvider , pageSize , modelSource ) { const createLoader = useCallback ( ( ) => new PagedTreeNodeLoader ( dataProvider , modelSource , pageSize ) , [ dataProvider , modelSource , pageSize ] ) ; return useDisposable ( createLoader ) ; } note public export function useTreeModelSource ( dataProvider ) { return useMemo ( ( ) => new TreeModelSource ( ) , [ dataProvider ] ) ; } note public export function useTreeEventsHandler < TEventsHandler extends TreeEventHandler > ( factoryOrParams ) { const factory = useCallback ( ( ) : TreeEventHandler => { if ( typeof factoryOrParams === "function" ) return factoryOrParams ( ) ; return new TreeEventHandler ( factoryOrParams ) ; } , [ factoryOrParams ] ) ; return useDisposable ( factory ) ; }