@empathyco/x-components
Version:
Empathy X Components
27 lines (15 loc) • 1.29 kB
Markdown
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) > [@empathyco/x-components](./x-components.md) > [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)<!-- --><Context, Request, Response> | |
**Returns:**
[FetchAndSaveActions](./x-components.fetchandsaveactions.md)<!-- --><Context, Request>
An action to fetch and save some data, and an action to cancel the last request.