@gluedigital/ruse-fetch-extras
v1.2.10
Published
Extra utilities for ruse-fetch
Downloads
25
Readme
ruse-fetch-extras
Extra utilities for ruse-fetch.
API
useFetch
/ useFetchCb
These methods are similar to the ones from ruse-fetch
, but they add:
- Support for JSON bodies: set
body
to an object, and it will serialize it, and set the content-type - Support for GET params: set
params
to an object, and it will be converted to a query string and added to the url - Auto-add the user token from the store: just save it at
store.user.token
useFetchUncachedCb
Similar to useFetchCb
, but does not dispatch anything. This is similar to calling plain fetch, but with all the additions above.
usePaginatedFetch
This hook helps deal with "infinite scroll" use cases. It works like useFetch
, but returns an object with the following fields:
data
: The aggregated results from the pages loaded so farpage
: The last page loadedisLoadingMore
: Indicates if we are loading a new pagehasNext
: Indicates if there are more pages to loadloadMore
: Function to load the next page of results
The behaviour for concatenating pages and detecting the last page can be customised with the merger
and hasNext
options
useCRUD
Provides CRUD methods for an entity. It assumes the standard REST URLs for each method.
usePeriodicFetch
Similar to useFetch
, but updates the data automatically with the specified period.
Please note that this method does not de-duplicate calls with the same URL.