import { useContext , useMemo } from 'react' ; import defaults from 'lodash/defaults' ; import ListContext from './ListContext' ; import { ListControllerProps } from './useListController' ; import { Record } from '../types' ; typedef ListControllerProps prop { Object } data prop { Array } ids prop { integer } total prop { boolean } loaded prop { boolean } loading prop { integer } page prop { Function } setPage prop { integer } perPage prop { Function } setPerPage prop { Object } currentSort prop { Function } setSort prop { Object } filterValues prop { Function } setFilters prop { Object } displayedFilters prop { Function } showFilter prop { Function } hideFilter prop { Array } selectedIds prop { Function } onSelect prop { Function } onToggleItem prop { Function } onUnselectItems prop { string } basePath prop { string } defaultTitle prop { string } resource returns { ListControllerProps } see useListController example example const useListContext = < RecordType extends Record = Record > ( props ? ) : ListControllerProps < RecordType > => { const context = useContext ( ListContext ) ; return useMemo ( ( ) => defaults ( { } , props != null ? extractListContextProps ( props ) : { } , context ) , [ context , props ] ) ; } ; export default useListContext ; param { Object } props returns { ListControllerProps } const extractListContextProps = ( { basePath , currentSort , data , defaultTitle , displayedFilters , filterValues , hasCreate , hideFilter , ids , loaded , loading , onSelect , onToggleItem , onUnselectItems , page , perPage , refetch , resource , selectedIds , setFilters , setPage , setPerPage , setSort , showFilter , total , } ) => ( { basePath , currentSort , data , defaultTitle , displayedFilters , filterValues , hasCreate , hideFilter , ids , loaded , loading , onSelect , onToggleItem , onUnselectItems , page , perPage , refetch , resource , selectedIds , setFilters , setPage , setPerPage , setSort , showFilter , total , } ) ;