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

145
Visualizações
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 Respostas
Responde à pergunta

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 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