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

242
Vistas
how can I passing data between the sibling component in React.js

I have search box that store a search value in state , also I want to send this value to anthore component that is sibling with nav-bar .how can I do that ? this is my code

1-part one

const Nav = () => {
const [searched,setSearched] = useState();
return (
    <div className={style.main}>
        <input className={style.search} type="text" value={searched} onChange={(event)=>{setSearched(event.target.value)}} />
    </div>
);}

2-part two : sibling component

const Now_Weather = () => {
const [weather,setWeather] = useState({null})

useEffect(()=>{
    const setapi =async()=>{
        const data = await (current_name()); //I need to pass "searched" from nav-bar to here
        setWeather(data); //set resault of current_name() in waether.

    }
    setapi();
},[weather])

there is on solution use Context-api but I don't want to implement that.

Do you know another ways ?

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

0

Lift the state up.

Move const [searched,setSearched] = useState(); to a shared ancestor component.

Pass searched as prop to Now_Weather.

Pass setSearched and searched as props to Nav.

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