import { useState } from 'react' ; import { TreeFocusable , TreeNodeId , TreeNodeProps , TreeSelectableType } from '../../Tree' ; interface UseFocusableProps < T > { nodes : TreeNodeProps < T > [ ] ; type : TreeSelectableType ; defaultSelected ? : TreeNodeId [ ] ; } export const useFocusable = < T > ( { nodes , type , defaultSelected } ) => { const [ focusedNode , setFocusedNode ] = useState ( type && defaultSelected ?. length ? defaultSelected [ 0 ] : nodes [ 0 ] . id ) ; const onFocus = ( nodeId ) => { setFocusedNode ( nodeId ) ; } ; return { focusedNode , onFocus } ; } ;