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

152
Views
How to update a component's prop which has been saved in a const

I have a parent component which is like this :

function parentComponent(){
     const [selectedValue,setSelectedValue] = useState();
     
     const [renderComponent,setRenderComponent] =[
           {
            name:'A' ,
            component : <ChildComponent values={selectedValue}/>
           },
           {
            name:'B' ,
            component : <OtherComponent/>
           },
     ]
     
    useEffect(()=>{
    
     const response = api('someapi');
     //i can get the response correctly and save it to state
     if(response.status===200){
     setSelectedValue(response.data);
     }
    },[])

    return <>{renderComponent[0].component}</>
     
}

and my child component is :

function childComponent({values}){
console.log('Props value is : ', values)

return <h3>Something</h3>

}

The problem is props are not updating and continue to return 'undefined' even after I update the state from the parent component

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

 

     useEffect(()=>{
       //set your state only after api data is completely fetched
   
         api('someapi').then((response)=>{
         console.log(response);// make sure this is not undefined
   
    if(response.status===200){
        setSelectedValue(response.data); 
        }
   }); 
   },[])
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!