import get from 'lodash/get' ; import { Identifier , Record , ReduxState , UseDataProviderOptions , } from '../types' ; import { useQueryWithStore , Refetch } from './useQueryWithStore' ; param resource param id param options param { boolean } options . enabled param { Function } options . onSuccess param { Function } options . onFailure returns example const useGetOne = < RecordType extends Record = Record > ( resource , id , options ? ) : UseGetOneHookValue < RecordType > => useQueryWithStore ( { type : 'getOne' , resource , payload : { id } } , options , ( state ) => { if ( Object . keys ( state . admin . resources ) . length > 0 && ! state . admin . resources [ resource ] ) { throw new Error ( `No <Resource> defined for "${ resource }". useGetOne() relies on the Redux store, so it cannot work if you don't include a <Resource>.` ) ; } return get ( state , [ 'admin' , 'resources' , resource , 'data' , id ] ) ; } ) ; export type UseGetOneHookValue < RecordType extends Record = Record > = { data ? : RecordType ; loading : boolean ; loaded : boolean ; error ? : any ; refetch : Refetch ; } ; export default useGetOne ;