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

151
Views
Cómo actualizar el accesorio de un componente que se ha guardado en una constante

Tengo un componente principal que es así:

 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}</> }

y mi componente hijo es:

 function childComponent({values}){ console.log('Props value is : ', values) return <h3>Something</h3> }

El problema es que los accesorios no se actualizan y continúan devolviendo 'indefinido' incluso después de actualizar el estado del componente principal

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!