useAsyncListing
SourceExecute an asynchronous call and return the value which can optionally be paginated.
If the result is paginated you can pass paginator
. Whenever the paginator state
is changed the function will be called unless trigger
is MANUAL
. You can pass
accumulatePages
to accumulate results for sequential pages returned from execute
.
This is useful to implement things like infinite scroll. If a non-sequential page
is accessed or query
changes then accumulated results will be cleared.
Parameter | Type | Description | |
---|---|---|---|
props.accumulatePages | boolean | Whether to accumulate pages as more results are fetched. For example if the first page of results is returned, then the next page is fetched then the combined results for the first two pages will be resolved. This resets whenever If this is true you must specify | |
* | props.execute | Function | Asynchronous function that returns the result for the query. Passed an
object with Note that when |
props.paginator | PaginatorInterface|null | Optional paginator if result is paginated. This will be monitored for
any state changes which will trigger a call to Required if | |
props.query | Record | Any query string parameters for the request | |
props.trigger | "MANUAL"|"DEEP" | When to trigger the fetch. Defaults to If set to Defaults to 'DEEP'. |
One of the following:
Key | Type | Description |
---|---|---|
isLoading | boolean | True while |
paginator | null|PaginatorInterface | The same |
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 |
run | Function | A function to manually trigger the action. If This function will return a promise that resolves/rejects to same value
returned by |
error | null | Until first call has resolved neither error nor result will be set |
result | null |
OR
Key | Type | Description |
---|---|---|
isLoading | boolean | True while |
paginator | null|PaginatorInterface | The same |
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 |
run | Function | A function to manually trigger the action. If This function will return a promise that resolves/rejects to same value
returned by |
error | Error | Set to the rejected value of the promise. Only one of |
result | null | Result will not be set when error is set |
OR
Key | Type | Description |
---|---|---|
isLoading | boolean | True while |
paginator | null|PaginatorInterface | The same |
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 |
run | Function | A function to manually trigger the action. If This function will return a promise that resolves/rejects to same value
returned by |
error | null | Error will not be set when result is set |
result | T | The value returned from execute |