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

264
Views
Why actions in reduxjs-toolkit are not exported ? (Reactjs - reduxToolkit)

I am using @reduxjs/toolkit and reactjs to build a shopping cart, and when I export the actions from Cart.js and try to import them into other files like cart.jsx and header.jsx, it says : Error statement

and when check the CONSOLE after clicking on the addTocart button which call the imported action of addToCart, it says: console error

this is cart.js (located in redux folder) code:

import { createSlice } from "@reduxjs/toolkit";

export const cartSlice = createSlice({
  name: "cart",
  initialState: {
    cartProds: []
    },
  reducers: {
    addToCart: (state, {payload})=>{
       const exist = state.cartProds.find(prod => prod.id === payload.id);
       if(exist){
            return  state.cartProds.map(prod => prod.id === payload.id ? {...prod, quantity: prod.quantity + 1}: prod);
       }
       if(!exist){
        return  state.cartProds = [...state, {...payload, quantity: 1}];
       }
    },
    removeFromCart :(state, {payload}) =>{
        const exist1 = state.find( prod => prod.id === payload.id);
        if(exist1.quantity === 1){
            return state.filter(prod => prod.id !== exist1.id);
        }else{
            return state.map(prod => prod.id === payload.id ? {...prod, quantity:prod.quantity-1}: prod);
        }
    }
  }
});

export const { addTocart, removeFromCart } = cartSlice.actions;
export default cartSlice.reducer;

and this is the way I imported them (the path is absolutely correct ! ):

import { addToCart, removeFromCart } from '../redux/cart.js';

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

0

You have exported addTocart (however in createSlice -> reducers you have addToCart)

export const { addTocart, removeFromCart } = cartSlice.actions;

and imported addToCart

import { addToCart, removeFromCart } from '../redux/cart.js';

Case-sensitivity!

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!