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

142
Views
Post Request not working with React, Redux and Ducks

I'm building an app with React, TS, Redux and Ducks (https://github.com/erikras/ducks-modular-redux)

I have several actions and reducers already built. But I am finding some troubles with the Post actions. I will leave you the code here as an example:

export const getChallenges: ReduxActionCreator = () => async (dispatch, getState) => {
  try {
    const data = await ApiClient.get('/challenges');
    console.log('get', data);
    dispatch({
      type: types.GET_CHALLENGES_SUCCESS,
      payload: data.data,
    });
  } catch (error) {
    console.log(error);
  }
};

export const postChallenges: ReduxActionCreator = (body) => async (dispatch, getState) => {
  try {
    const data = await ApiClient.post('/challenges', body);
    console.log('post', data);
    dispatch({
      type: types.ADD_CHALLENGE_SUCCESS,
      payload: data.data,
    });
  } catch (error) {
    console.log(error);
  }
};

So, getChallenges is working fine and I already render it in the browser.

For some reason, postChallenges is not even firing in Redux devtools, not even giving me an error.

I'm calling it simply like this:


  const dispatch = useDispatch();

  const handleSubmitForm = () => {
    dispatch(postChallenges(values));
    push(Path.AddMissions);
  };


ApiClient code

import axios from 'axios';

export const ApiClient = axios.create({
  baseURL: 'https://thnk.gendesa.genit.com.ar/api/v1/',
  timeout: 20 * 1000,
  headers: {
    'Content-Type': 'application/json',
  },
});

ApiClient.interceptors.response.use(
  (response) => response.data,
  (error) => Promise.reject(error),
);

Any ideas?

Thanks!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Thanks everybody for your questions and suggestions. I'll definetely check the ducks documentation to improve the code once I have the time.

Regarding the solution, it was so simple:

Just adding the challenges reducer to the store.

const composeEnhancers = (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;

const rootReducer = combineReducers({
  assesments: assessmentsReducer,
  auth: authReducer,
  events: eventsReducer,
  elements: elementsReducer,
  challenges: challengesReducer,
  questions: questionsReducer,
  surveys: surveysReducer,
  missions: missionsReducer,
});

export const store = createStore(rootReducer, composeEnhancers(applyMiddleware(thunk)));

export type RootState = ReturnType<typeof store.getState>;
export type AppDispatch = typeof store.dispatch;

Thanks for taking your time to read my question

Kindly,

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!