Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

153
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda