import { useState , useEffect } from 'react' ; import { Subscription } from 'rxjs' ; import { DataPublicPluginStart , Filter } from '../../..' ; interface UseFilterManagerProps { filters ? : Filter [ ] ; filterManager : DataPublicPluginStart [ 'query' ] [ 'filterManager' ] ; } export const useFilterManager = ( props ) => { const [ filters , setFilters ] = useState ( props . filters || props . filterManager . getFilters ( ) ) ; useEffect ( ( ) => { const subscriptions = new Subscription ( ) ; subscriptions . add ( props . filterManager . getUpdates$ ( ) . subscribe ( { next : ( ) => { const newFilters = props . filterManager . getFilters ( ) ; setFilters ( newFilters ) ; } , } ) ) ; return ( ) => { subscriptions . unsubscribe ( ) ; } ; } , [ props . filterManager ] ) ; return { filters } ; } ;