Skip to content

Commit 1a08211

Browse files
committed
added docs
1 parent 7473e93 commit 1a08211

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

docs/api/createAsyncThunk.mdx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,18 @@ When dispatched, the thunk will:
133133
- if the promise failed and was not handled with `rejectWithValue`, dispatch the `rejected` action with a serialized version of the error value as `action.error`
134134
- Return a fulfilled promise containing the final dispatched action (either the `fulfilled` or `rejected` action object)
135135

136+
## Thunk Dispatch Options
137+
138+
The returned thunk action creator accepts an optional second argument with the following options:
139+
140+
- `signal`: an optional [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) that can be used to cancel the request if needed.
141+
142+
```ts
143+
const externalController = new AbortController()
144+
dispatch(fetchUserById(123, { signal: externalController.signal }))
145+
externalController.abort()
146+
```
147+
136148
## Promise Lifecycle Actions
137149

138150
`createAsyncThunk` will generate three Redux action creators using [`createAction`](./createAction.mdx): `pending`, `fulfilled`, and `rejected`. Each lifecycle action creator will be attached to the returned thunk action creator so that your reducer logic can reference the action types and respond to the actions when dispatched. Each action object will contain the current unique `requestId` and `arg` values under `action.meta`.

0 commit comments

Comments
 (0)