import { useCallback , useState } from 'react' ; import { useMlKibana } from '../kibana' ; import type { MlStorageKey } from '../../../../common/types/storage' ; param key param initValue export function useStorage < T > ( key , initValue ? ) { const { services : { storage } , } = useMlKibana ( ) ; const [ val , setVal ] = useState < T > ( storage . get ( key ) ?? initValue ) ; const setStorage = useCallback ( ( value ) : void => { try { storage . set ( key , value ) ; setVal ( value ) ; } catch ( e ) { throw new Error ( 'Unable to update storage with provided value' ) ; } } , [ ] ) ; return [ val , setStorage ] ; }