Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

768
Visualizações
Error: Actions must be plain objects. Use custom middleware for async actions. Redux toolkit

I have the following code with redux-toolkit but i can't find the error

if (token) { // this code dispatches the function below in a different file
  const data = {
    service: 'stripe',
    stripe_payment_id: token.id,
  };
  dispatch(setPaymentMethod({ data, tenantId: tenant.id }));
}

export const setPaymentMethod = (params: any) => {
  const { data, tenantId } = params;
  return async (dispatch: any, getState: any) =>
    dispatch(
      postRequest(
        `${API.TENANTS}/${tenantId}/${API.PAYMENT_METHODS}`,
        data,
        response => console.log(response),
      ),
    );
};

The code above calls the API handler file like this

const postRequest = async (
  url: string,
  body: any,
  onSuccess: (x: any) => void,
  onError?: () => void,
  params?: any,
) => {
  return async (dispatch: any, getState: any) => {
    try {
      let response = await API.post(url, body, {});
      if (response.status === 200) {
        console.log(response);
        onSuccess(response.data);
      }
    } catch (error) {
      console.log(error);
    }
  };
};

Maybe I am not seeing the error and it seems easy to fix but haven't found the solution, please help!

I am using redux-toolkit which uses redux-thunk behind the scenes already

/Store config

const rootReducer = combineReducers({
  /* PLOP_INJECT_EXPORT */
  tenantsReducer: tenantsSlice,
  receiptsReducer: receiptsSlice,
  geoLocationReducer: geoLocationSlice,
  storesReducer: storesSlice,
  authReducer: authSlice,
  exampleReducer: exampleSlice,
  uiReducer: uiSlice,
  tokensReducer: tokensSlice,
  [usersApi.reducerPath]: usersApi.reducer,
});

const persistConfig = {
  key: 'root',
  version: 1,
  storage: AsyncStorage,
  // whitelist: ['uiReducer'],
};

const persistedReducer = persistReducer(persistConfig, rootReducer);

const store = configureStore({
  reducer: persistedReducer,
  middleware: getDefaultMiddleware =>
    getDefaultMiddleware({
      serializableCheck: {
        ignoredActions: [FLUSH, REHYDRATE, PAUSE, PERSIST, PURGE, REGISTER],
      },
    }),
});

setupListeners(store.dispatch);
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Redux-Thunk doesn't handle promises out of the book. Check createAsyncThunk.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda