import { useMemo } from 'react' ; import { RxCollection , RxQuery , RxDocument } from 'rxdb' ; import { Override } from './type.helpers' ; import useRxCollection from './useRxCollection' ; import useRxQuery , { UseRxQueryOptions , RxQueryResult , RxQueryResultJSON , RxQueryResultDoc , } from './useRxQuery' ; export type QueryConstructor < T > = ( collection : RxCollection < T > ) => RxQuery < T , RxDocument < T > > | RxQuery < T , RxDocument < T > [ ] > | undefined ; function useRxData < T > ( collectionName , queryConstructor ) ; function useRxData < T > ( collectionName , queryConstructor , options ? ) ; function useRxData < T > ( collectionName , queryConstructor , options ? ) ; /**
 * Convenience wrapper around useRxQuery that expects a collection name
 * & a query constructor function
 */ function useRxData < T > ( collectionName , queryConstructor , options = { } ) { const collection = useRxCollection < T > ( collectionName ) ; const query = useMemo ( ( ) => { if ( ! collection || typeof queryConstructor !== 'function' ) { return null ; } return queryConstructor ( collection ) ; } , [ collection , queryConstructor ] ) ; return options . json ? useRxQuery ( query , { ... options , json : true } ) : useRxQuery ( query , { ... options , json : false } ) ; } export default useRxData ;