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

199
Views
items not getting added in cart using react-redux

I want to add items to the cart using redux, its not getting added neither its showing any error. please help me out. Below is my code

this is cartItem.js

export const ADD_TO_CART = 'ADD_TO_CART'
export const REMOVE_FROM_CART = 'REMOVE_FROM_CART'


const initialState = []

const cartItemsReducer = (state = initialState, action) => {
  switch (action.type) {
    case ADD_TO_CART:
      return [...state, action.payload]
    case REMOVE_FROM_CART:
      return state.filter(cartItem => cartItem.id !== action.payload.id)
  }
  return state
}

export default cartItemsReducer

this is store.js

import { createStore } from 'redux'
import cartItemsReducer from './CartItem'

const store = createStore(cartItemsReducer)

export default store

this is App.js

import React from 'react'
import MainStackNavigator from './src/navigation/AppNavigator'
import { Provider as StoreProvider } from 'react-redux'
import store from './src/redux/Store'

export default function App() {
  
  return (
    <StoreProvider store={store}>
      <MainStackNavigator />
    </StoreProvider>
  )
}

this is screen where I am dispatching

import  ADD_TO_CART from '../redux/CartItem'
import { useDispatch } from 'react-redux'

const dispatch = useDispatch()
    
const addItemToCart = item => dispatch({ type: ADD_TO_CART, payload: item })

<TouchableOpacity onPress={() => addItemToCart(item)} style={styles.button}>
                                    
<Text style={styles.buttonText}>Add +</Text>
                                
</TouchableOpacity>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You're invoking the function with an item parameter, but where is it coming from?

You must define the parameter and then pass it.

<TouchableOpacity onPress={(item) => addItemToCart(item)} style=
{styles.button}>
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!