React hook to use data from a data provider. Subscribes to run a callback on a data provider's
data with specified selector on the specified data type that data provider serves.
Usage: Specify the data provider and the data type on the data provider with
useData('<data_provider>').<data_type> and use like any other React hook.
@example Subscribing to Verse data at JHN 11:35 on the 'quickVerse.quickVerse' data provider:
@paramdataProviderSource string name of data provider to get OR dataProvider (result of
useDataProvider if you want to consolidate and only get the data provider once)
@paramselector tells the provider what data this listener is listening for
WARNING: MUST BE STABLE - const or wrapped in useState, useMemo, etc. The reference must not be
updated every render
@paramdefaultValue the initial value to return while first awaiting the data
@paramsubscriberOptions various options to adjust how the subscriber emits updates
Note: this parameter is internally assigned to a ref, so changing it will not cause any hooks
to re-run with its new value. This means that subscriberOptions will be passed to the data
provider's subscribe<data_type> method as soon as possible and will not be updated again until
dataProviderSource or selector changes.
@returns[data, setData, isLoading]
data: the current value for the data from the data provider with the specified data type and
selector, either the defaultValue or the resolved data
setData: asynchronous function to request that the data provider update the data at this data
type and selector. Returns true if successful. Note that this function does not update the
data. The data provider sends out an update to this subscription if it successfully updates
data.
isLoading: whether the data with the data type and selector is awaiting retrieval from the data
provider
React hook to use data from a data provider. Subscribes to run a callback on a data provider's data with specified selector on the specified data type that data provider serves.
Usage: Specify the data provider and the data type on the data provider with
useData('<data_provider>').<data_type>
and use like any other React hook.@example Subscribing to Verse data at JHN 11:35 on the
'quickVerse.quickVerse'
data provider:@param
dataProviderSource
string name of data provider to get OR dataProvider (result of useDataProvider if you want to consolidate and only get the data provider once)@param
selector
tells the provider what data this listener is listening forWARNING: MUST BE STABLE - const or wrapped in useState, useMemo, etc. The reference must not be updated every render
@param
defaultValue
the initial value to return while first awaiting the data@param
subscriberOptions
various options to adjust how the subscriber emits updatesNote: this parameter is internally assigned to a
ref
, so changing it will not cause any hooks to re-run with its new value. This means thatsubscriberOptions
will be passed to the data provider'ssubscribe<data_type>
method as soon as possible and will not be updated again untildataProviderSource
orselector
changes.@returns
[data, setData, isLoading]
data
: the current value for the data from the data provider with the specified data type and selector, either thedefaultValue
or the resolved datasetData
: asynchronous function to request that the data provider update the data at this data type and selector. Returnstrue
if successful. Note that this function does not update the data. The data provider sends out an update to this subscription if it successfully updates data.isLoading
: whether the data with the data type and selector is awaiting retrieval from the data provider