Files
react-starter-kit/src/features/examples/counter/state/actions/incrementAsync.ts
Mastermindzh 8496f5cfbe Moved examples into example directory
Moved routes to separate file
Used route constants
2022-07-26 10:32:11 +02:00

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;
});