Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

767
Views
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 answers
Answer question

0

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

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!