useAsyncValue
SourceResolve a value from an id using an async function.
For the specified id
the resolve
function will be called and should
return the value for the specified id.
If existingValues
is provided this will be consulted first before calling
resolve
. This is useful when you have a list of values that may or
may not have the data you care about. If it's there then the value will
be returned immediately.
For multiple values see documentation below.
Parameter | Type | Description | |
---|---|---|---|
props.existingValues | T[] | An optional array of existing values to try and find the value in. If each item does not implement Identifiable then you
must provide the You can use this to avoid resolving data that already exists. If dealing with ViewModel instances you can use it with useViewModelCache, eg.
| |
props.getId | Function | A function that returns a unique ID for each item in | |
props.onError | Function | Called when | |
props.onSuccess | Function | Called when | |
props.trigger | "MANUAL"|"DEEP" | When to trigger the fetch. Defaults to If set to | |
* | props.id | Id|null | Single If you need to resolve multiple values use the other form documented
below passing |
* | props.resolve | Function | Resolve the value for the provided ID. Function is passed a single parameter
being Note that when |
Key | Type | Description |
---|---|---|
error | null|Error | Set to the rejected value of the promise. Only one of |
isLoading | boolean | True while |
reset | Function | When called will set both result and error to null. Will not immediately trigger
a call to the action but subsequent changes to query or paginator will according
to the value of If value is found in |
run | Function | A function to manually trigger the action. If This function will return a promise that resolves/rejects to same value
returned by |
value | T|null | The resolved value |
Resolve values from an array of ids using an async function.
For the specified array of ids
the resolve
function will be called
and should return an array of the same size with each entry being the resolved
value for the corresponding id.
If existingValues
is provided this will be consulted first before calling
resolve
. This is useful when you have a list of values that may or
may not have the data you care about. If it's there then the values will
be returned immediately. Note that if any of the ids are missing from
existingValues
then it will be ignored and a call to resolve
will be made
requesting values for all ids
.
Parameter | Type | Description | |
---|---|---|---|
props.existingValues | T[] | An optional array of existing values to try and find the value in. If each item does not implement Identifiable then you
must provide the You can use this to avoid resolving data that already exists. If dealing with ViewModel instances you can use it with useViewModelCache, eg.
| |
props.getId | Function | A function that returns a unique ID for each item in | |
props.onError | Function | Called when | |
props.onSuccess | Function | Called when | |
props.trigger | "MANUAL"|"DEEP" | When to trigger the fetch. Defaults to If set to | |
* | props.ids | Id[]|null | Array of ids to resolve values for or null if nothing yet to resolve If you need to resolve a single value use the other form documented above
passing |
* | props.resolve | Function | Resolve the value for the provided IDs. Function is passed a single parameter
being |
Key | Type | Description |
---|---|---|
error | null|Error | Set to the rejected value of the promise. Only one of |
isLoading | boolean | True while |
reset | Function | When called will set both result and error to null. Will not immediately trigger
a call to the action but subsequent changes to query or paginator will according
to the value of If value is found in |
run | Function | A function to manually trigger the action. If This function will return a promise that resolves/rejects to same value
returned by |
value | T|null | The resolved value |