Query NerdStorage for user scoped data.
Retrieve an entire collection or a single document.
Usage
import { UserStorageQuery } from 'nr1'
Examples
Query collection
1<UserStorageQuery collection="foo">2 {({ loading, error, data }) => {3 if (loading) {4 return <Spinner />;5 }67 if (error) {8 return 'Error!';9 }1011 return <pre>{JSON.stringify(data, null, 4)}</pre>;12 }}13</UserStorageQuery>;
Query document
1<UserStorageQuery collection="foo" documentId="bar">2 {({ loading, error, data }) => {3 if (loading) {4 return <Spinner />;5 }67 if (error) {8 return 'Error!';9 }1011 return <pre>{JSON.stringify(data, null, 4)}</pre>;12 }}13</UserStorageQuery>;
Imperative query
1UserStorageQuery.query({2 collection: 'mycollection',3 documentId: 'mydocumentID',4}).then(({ data }) => console.log(data));
Props
Render prop function as a child.
function (queryResult: {Object // Results of the query.
) => undefined
Name of the collection to query.
ID of the document to retrieve.
If omitted, the whole collection is returned.
UserStorageQuery .FETCH_POLICY_TYPE .CACHE_AND_NETWORK
Fetch policy to be used for the query.
Allows you to specify how you want your query to interact with the cached data.
CACHE_AND_NETWORK
: The query returns your initial data from the cache if available. However, regardless of whether or not the full data is in your cache, the query always makes a request using your network interface and returns the updated data. This option is not available when using the staticquery()
method of the component.CACHE_FIRST
: The query makes a request using your network interface only if the data for your query is not already in the cache.CACHE_ONLY
: The query never makes a request using your network interface. Instead it returns the data available in the cache. If the data for your query does not exist in the cache, then an error is thrown.NETWORK_ONLY
: The query never returns your initial data from the cache. Instead it always makes a request using your network interface.NO_CACHE
: The query never returns your initial data from the cache. Instead it always makes a request using your network interface. Unlike theNETWORK_ONLY
policy, it does not write any data to the cache after the query completes.
<One ofUserStorageQuery.FETCH_POLICY_TYPE.CACHE_AND_NETWORK,UserStorageQuery.FETCH_POLICY_TYPE.CACHE_FIRST,UserStorageQuery.FETCH_POLICY_TYPE.CACHE_ONLY,UserStorageQuery.FETCH_POLICY_TYPE.NETWORK_ONLY,UserStorageQuery.FETCH_POLICY_TYPE.NO_CACHE,>
0
Interval in milliseconds to poll for new data.
Methods
UserStorageQuery.render
function () => undefined
UserStorageQuery.query
A static method to use UserStorageQuery as a Promise instead of as a React component.
function (props: Object // An object containing the query options. Any
UserStorageQuery
prop is a valid option except children
and pollInterval
.
) => {Object}
Type definitions
PromiseQueryResult
{loading: boolean, // Indicates that the request is in flight.
data: Object, // An object containing the result of your query.
}