import { useContext , useEffect , useState } from 'react' ; import { SearchContext } from '@elastic/react-search-ui' ; export const useSearchContextState = ( ) => { const { driver } = useContext ( SearchContext ) ; const [ state , setState ] = useState ( driver . state ) ; useEffect ( ( ) => { driver . subscribeToStateChanges ( ( newState ) => { setState ( newState ) ; } ) ; return ( ) => { driver . unsubscribeToStateChanges ( ) ; } ; } , [ state ] ) ; return state ; } ; export const useSearchContextActions = ( ) => { const { driver } = useContext ( SearchContext ) ; return driver . actions ; } ;