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

94
Vistas
How do I pass the data totalAmount from the child to parent to another child component again?

I have this totalAmount data from the cart.js and how can I pass it to the parent component(app.js) where I will be able to pass it to another child component(info.js). I tried passing it from the Cart.js to the parent, it won't work, this is what it would display:

Identifier 'totalAmount' has already been declared

codesandbox: https://codesandbox.io/s/add-to-cart-sampled-2-with-material-ui-table-pagination-with-reduced-cart-items-firebase-5id6gs?file=/src/Cart.js**strong text**

In the cart.js

const Cart = ({ cartItems, handleCartClearance, handleRemove, handleAdd }) => {

  const totalAmount = cartItems.reduce(
    (price, item) => price + item.quantity * item.price,
    0
  );

  return (
    <div>

    </div>
  );
};

export default Cart;

In the App.js How can I pass the totalAmount to the customerInfo component?

export default function App() {

  return (
    <div className="App">
      <CustomerInfo cartItems={cartItems} /> 
      <br />
          <Cart
            cartItems={cartItems}
            handleCartClearance={handleCartClearance}
            handleRemove={handleRemove}
            handleAdd={handleAdd}
          />
      </Stack>
    </div>
  );
}

CustomerInfo component:

const CustomerInfo = ({ cartItems }) => {
  const handleSubmit = (e) => {
    e.preventDefault();
    console.log(firstName, number, "info");
    console.log(cartItems, "cartItems, info");
    //console the totalAmount here
  };

  return (
    <Container style={{ padding: "12px" }}>

    </Container>
  );
};

export default CustomerInfo;
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Since totalAmount calcul is only based on cartItems, which is a prop of Cart. I do believe this is not the responsibility of Cart to calcul it but the responsibility of its parent.

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