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

293
Vistas
react js - passing an array of objects using router

I am trying to set up a fake shopping cart. I have an array of objects. Each object is a fruit's name, price and quantity.

On one page, I displayed these items and their quantities and allow the user to adjust the values. After clicking checkout, I would like to use React Router to another page that will display the final price and quantities for each fruit and a total sum on another page.

Is there any tips for this? I can't find a solution to passing an array of objects across pages but I can find some for sending state with specific values.

code:

const Inventory = () => {
    const [inventory, setInventory] = useState(
        [
            {
                id:0,
                name: "lemons",
            
                count: 0,
                cost: 5.25
            },

            {
                id:1,
                name: "apples",
               
                count: 0,
                cost: 2.25
            },
            {
                id:2,
                name: "bananas",
                
                count: 0,
                cost: 1.00
            },
            {
                id:3,
                name: "avocado",
                
                count: 0,
                cost: 11.50
            },
        ]);

 return (
        <div>
            <h1>This is another items page</h1> 
            <ul className = "links">
                <Link to = "/">
                    <li> Home</li>
                </Link>
                <Link to = "/cart">
                   <li> Checkout </li>
                </Link>
            </ul>
)
}
about 4 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 Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda