redux-toolkit

Redux-Toolkit createAsyncThunk Dispatch is showing as undefined

戏子无情 提交于 2020-07-10 07:01:19
问题 Using Redux-Toolkit, I am trying to use ThunkAPI & dispatch inside an createAsyncThunk but I am getting rejected because of type error. Not sure how to resolve this. my store: export const store = configureStore({ reducer: rootReducer, middleware: [...getDefaultMiddleware()], }); my Action: export const tester = createAsyncThunk( 'tester', async (testData, {dispatch}) => { await dispatch(load(true)); const final = await someExternalFunc(testData) return final; } ); but, I am getting output as

How do I resolve 'Property 'type' is missing in type 'AsyncThunkAction' using Redux Toolkit (with TypeScript)?

爷,独闯天下 提交于 2020-06-17 15:49:09
问题 I'm using Redux Toolkit with the thunk/slice below. Rather than set the errors in state, I figure I could just handle them locally by waiting for the thunk promise to resolve, using the example provided here. I guess I could avoid doing this, and perhaps I should, by setting an error in the state but I sort of want to understand where I went wrong on this. Argument of type 'AsyncThunkAction<LoginResponse, LoginFormData, {}>' is not assignable to parameter of type 'Action<unknown>'. Property

Redirect page upon login using react-router-v5 and redux-toolkit

橙三吉。 提交于 2020-06-11 15:11:53
问题 I'm using react-router-dom v5.2. Upon login, I want my page to redirect to /home from / . The login form is at / . When I try to perform authentication without any async function (ie. comparing username and password to hardcoded values in react), everything works perfectly. But when I do perform authentication using express and mongo, the redirection upon login stops working. If I login again, then the redirection happens. Protected routes still work (redirect to login page if the user is not

Redirect page upon login using react-router-v5 and redux-toolkit

允我心安 提交于 2020-06-11 15:11:03
问题 I'm using react-router-dom v5.2. Upon login, I want my page to redirect to /home from / . The login form is at / . When I try to perform authentication without any async function (ie. comparing username and password to hardcoded values in react), everything works perfectly. But when I do perform authentication using express and mongo, the redirection upon login stops working. If I login again, then the redirection happens. Protected routes still work (redirect to login page if the user is not

Rewrite redux-orm reducer with redux-toolkit

时光毁灭记忆、已成空白 提交于 2020-05-15 04:21:07
问题 Issue (tl;dr) How can we create a custom redux-orm reducer with redux-toolkit's createSlice? Is there a simpler, recommended, more elegant or just other solution than the attempt provided in this question? Details The example of a custom redux-orm reducer looks as follows (simplified): function ormReducer(dbState, action) { const session = orm.session(dbState); const { Book } = session; switch (action.type) { case 'CREATE_BOOK': Book.create(action.payload); break; case 'REMOVE_AUTHOR_FROM