Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

241
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!