UNPKG

@empathyco/x-components

Version:
27 lines (15 loc) 1.29 kB
<!-- Do not edit this file. It is automatically generated by API Documenter. --> [Home](./index.md) &gt; [@empathyco/x-components](./x-components.md) &gt; [createFetchAndSaveActions](./x-components.createfetchandsaveactions.md) ## createFetchAndSaveActions() function Utility to create an action that requests and save some data asynchronously, with the option to cancel the request at any moment. This factory provides with the standard flow for requesting, cancelling, handling errors for a module, while also taking care of its status. **Signature:** ```typescript export declare function createFetchAndSaveActions<Context extends XActionContext<StatusState, object, StatusMutations, object>, Request, Response>({ fetch, onSuccess, onError, onCancel, }: FetchAndSaveHooks<Context, Request, Response>): FetchAndSaveActions<Context, Request>; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | | { fetch, onSuccess, onError, onCancel, } | [FetchAndSaveHooks](./x-components.fetchandsavehooks.md)<!-- -->&lt;Context, Request, Response&gt; | | **Returns:** [FetchAndSaveActions](./x-components.fetchandsaveactions.md)<!-- -->&lt;Context, Request&gt; An action to fetch and save some data, and an action to cancel the last request.