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

199
Visualizações
Not store data in reducer after get data from api

I am trying to store data in my redux store using a reducer when we get data from B/E API and trying to store data in the reducer(store). But not working. My code is correct to me. But somehow it's not working.

My Store:-

import createSagaMiddleware from 'redux-saga';
import { configureStore } from '@reduxjs/toolkit';
import rootReducer from './rootReducer';
import rootSaga from './rootsaga';
// saga middleware
const sagaMiddleware = createSagaMiddleware();

// redux store
const store = configureStore({
  reducer: rootReducer,
  middleware: [sagaMiddleware],
});

// run saga middleware
sagaMiddleware.run(rootSaga);

export default store;

My root saga:-

import { all, takeEvery } from '@redux-saga/core/effects';
import * as categoryActionTypes from '../redux/types/categoryActionTypes';
import * as productActionTypes from '../redux/types/productActionTypes';
import { getAllStudents } from './sagas/categorySaga';
import { getAllProductWatcher } from './sagas/productSaga';

export default function* root() {
  yield all([
    takeEvery(categoryActionTypes.GET_ALL_CATEGORY, getAllStudents),
    takeEvery(productActionTypes.GET_ALL_PRODUCT_ACTION, getAllProductWatcher),
  ]);
}

My Reducer:- (console.log() not working) That's means not store data into reducer

import * as actionTypes from '../types/productActionTypes';

const initialState = {
  product: [],
  isLoading: true,
  error: true,
};

// reducer
export default function productReducer(state = initialState, action) {
  switch (action.types) {
    case actionTypes.GET_ALL_PRODUCT_SUCCESS:
      console.log(action.data);
      return {
        ...state,
        product: action.data,
        isLoading: false,
        error: false,
      };
    default:
      return state;
  }
}

This is my saga method and this is how I store data into my reducer:-

import { put } from '@redux-saga/core/effects';
import { GET_ALL_PRODUCT_SUCCESS } from '../types/productActionTypes';
import { createRequest } from '@utils/create-request';

export function* getAllProductWatcher(upload) {
  try {
    const Axios = yield createRequest(upload);
    const res = yield Axios.get('http://localhost:8080/product');
    if (res) {
     **//Tying to store API data to my reducer**
      yield put({
        type: GET_ALL_PRODUCT_SUCCESS,
        data: res.data,
      });
    }
  } catch (e) {
    console.log(e);
  }
}

I really need your help... Thanks.

about 4 years ago · Juan Pablo Isaza
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