getQuery
getQuery
is a selector which returns a state for a given query. It is the selector which requires props.
Imagine you want to get a state for FETCH_BOOKS
query which we played with earlier. You can use it like this:
import { getQuery } from '@redux-requests/core';
const booksQuery = getQuery(state, { type: 'FETCH_BOOKS' });/* for example { data: [{ id: '1', name: 'Some book title' }], loading: false, error: null, pristine: false, // true only when there was no request made for a give type pending: 0 // number of pending requests downloadProgress: null, // only when requestAction.meta.measureDownloadProgress is true uploadProgress: null, // only when requestAction.meta.measureUploadProgress is true} */
We only provided example for type
prop, but here you have the list of all possibilities:
type: string
: just pass query action type or action itself when using action creator libraryrequestKey: string
: use it if you usedmeta.requestKey
in query actionmultiple
: set totrue
if you preferdata
to be[]
instead ofnull
if data is empty,false
by defaultdefaultData
: use it to representdata
as an orbitrary object instead ofnull
, use top level object though, not recreate it multiple times not to break selector memoizationaction
: useful only when you use Typescript, see details here