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
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); } }); },[])