mirror of
https://github.com/Mastermindzh/react-starter-kit.git
synced 2025-08-23 09:35:01 +02:00
14 lines
706 B
TypeScript
14 lines
706 B
TypeScript
import { createAsyncThunk } from "@reduxjs/toolkit";
|
|
import { fetchCount } from "../../services/counterAPI";
|
|
|
|
// The function below is called a thunk and allows us to perform async logic. It
|
|
// can be dispatched like a regular action: `dispatch(incrementAsync(10))`. This
|
|
// will call the thunk with the `dispatch` function as the first argument. Async
|
|
// code can then be executed and other actions can be dispatched. Thunks are
|
|
// typically used to make async requests.
|
|
export const incrementAsync = createAsyncThunk("counter/fetchCount", async (amount: number) => {
|
|
const response = await fetchCount(amount);
|
|
// The value we return becomes the `fulfilled` action payload
|
|
return response.data;
|
|
});
|