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

217
Visualizações
How to check that a certain prop has received?

I have an synchronization issue. I want to check props is loaded or not to child component. I have wrote a code like that :

  componentDidMount() {
    setTimeout(() => {
      this.setState({
        editorContent: this.props.json[this.state.contentType],
      });
    }, 2500);
  }

Here I'm using 'setTimeout' function. In render function I'm using 'editorContent' state so this is undefined if I don't use 'setTimeout'. After 1 or 2 sec. props received and it won't be undefined. I guess there is better solution for that. Thanks all

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

This method is completely not sustainable instead you should use useEffect let me demonstrate by code in functional component.

//cildComponent.js
export default ChildComponent(props){
const [pending , setPending] = useState(true)
useEffect(()=>{
 if(props.name){
// now you have the name available
 setPending(false);
}
 },[props])
if(pending){
 return “loading”
 }
 return ‘your name is ${props.name}’
}
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