Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

200
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda