cossack910 / ReactJest

React Testing Library + JEST
0 stars 0 forks source link

createAsyncThunk #21

Open cossack910 opened 11 months ago

cossack910 commented 11 months ago

公式 https://redux-toolkit.js.org/api/createAsyncThunk#promise-lifecycle-actions

cossack910 commented 11 months ago

引数について https://times.hrbrain.co.jp/entry/2020/12/08/redux-toolkit-async-thunk

cossack910 commented 11 months ago

storeからdipatchの型を取得して使用する

store.tsでhooksをエクスポートする

使用するときは useAppDispatchをインポートするだけ

import { configureStore, combineReducers } from "@reduxjs/toolkit";
import customCounterReducer from "./customCounterSlice";
import { useDispatch } from "react-redux";

const rootReducer = combineReducers({
  customCounter: customCounterReducer,
});

export const store = configureStore({
  reducer: rootReducer,
});

export type RootState = ReturnType<typeof rootReducer>;
export type AppDispatch = typeof store.dispatch;
export const useAppDispatch: () => AppDispatch = useDispatch; ←これ、別にhooks.tsとか作ってそこに記載した方がいいかも