• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

219
Vistas
changing data from context consumer doesn't change the displayed data (React)

I'm implementing a shopping cart, that obviously will have a button to add more products. I implemented the cart context and the functionality works fine, but when I increase the number of the products to purchase it doesn't change the number displayed. What could my issue would be?

Here is my code for the context consumer

    render() {
    return (
        <CartContext.Consumer>
            {
                (cartContext =>{
                    const {addProduct} = cartContext
                        return(
                            <div>
                                <h1 key={this.props.product.itemId}> {this.state.product.name} </h1>
                                <button onClick={() => {addProduct(this.props.product.itemId)}}> Add </button>
                                <h4>{this.props.product.qty}</h4>
                                <hr/>
                            </div>
                        )
                })
            }
        </CartContext.Consumer>
    )
}
almost 3 years ago · Juan Pablo Isaza
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 Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda