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

135
Vistas
How to pass multiples states at the same time to a child component from parent component in Reactjs?

I am new to Reactjs and thanks in advance. I have the states below:

const [firstName, setFirstName]=useState();
const [lastName, setLastName]=useState();

I want to pass both firstName and lastName to the child component from the parent component at the same time. How could I do that?

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

You could do it this way, assuming that your components are called Parent and Child:

export default function Parent(){
   const [firstName, setFirstName]=useState();
   const [lastName, setLastName]=useState();
   
   return (
     <Child firstName={firstName} lastName={lastName} />
   )

}

And you get them inside Child like so:

export default function Child(props){

  console.log(props.firstName, props.lastName)
  return <div></div>
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

If you mean that you want to pass firstName and lastName to child element, relevant to component where you declared the states then you just need to pass them as props

<Child firstName={firstName} lastName={lastName} />

and inside child you would access them like props

function Child(props){

console.log(props) //this will show props of child component, there are stored your statements

return(...something here...)
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

See the react docs for components and props

Components accept arbitrary inputs (called “props”) and return React elements describing what should appear on the screen.

When React sees an element representing a user-defined component, it passes JSX attributes (and children) to this component as a single object. We call this object “props”.

import { useState } from "react";

function ParentComponent() {
  const [firstName, setFirstName] = useState("John");
  const [lastName, setLastName] = useState("Smith");
  return (
    <div className="ParentComponent">
      <ChildComponent firstName={firstName} lastName={lastName} />
    </div>
  );
}

function ChildComponent(props) {
  return (
    <div className="ChildComponent">
      <p>firstName: {props.firstName}</p>
      <p>lastName: {props.lastName}</p>
    </div>
  );
}

Demo

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