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

142
Visualizações
React initial state delay

I have a React project and I am fetching data from firebase directly on the client side. For the components that are using an initial state (which is usually set from firestore data), there is like 1 second delay on the component until the data is visible. For example, I have a paragraph "Welcome {username}". Username is being set in the useEffect by calling a function that fetches data from firestore. At first it appears blank and after 1 second, let's say, the username is visible. Is there anything I can do to fix this? I know it is due to the setState, but I am wondering if there is any fix.

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

0

I think that what you are looking for is not a fix, but a way to display things once they've been loaded.

What I would suggest is a conditional display. Something like :

  const [username, setUsername] = useState(null);

  useEffect(() => {
    yourMethodThatSetUsername();
  }, [])

  return (
    {
      username ? <YourComponent /> : null
    }
  )
about 4 years ago · Juan Pablo Isaza Relatório

0

Usually you set a state in the component from which you are calling useEffect, like this:

[loading, setLoading] = useState(true);

You can then conditionally render your component like this: loading ? //some progress component : Welcome ${username};

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