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

196
Views
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
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!