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

178
Visualizações
Wait till page is refreshed: React

I have a React Component, which has a button and when clicked a sidePane is opened. I would like to first refresh the page, wait till it completely gets refreshed and then open the sidepane. Here is my current code:

const refreshPage = () => {
  window.location.reload();
}

<button onClick={() => {
    refreshPage(); // Refreshing here and then opening the sidePane
    setIsPaneOpen(true);
}} className="btn-default">Click me</button>
                               

I have tried sleep and wait, but it depends on all factors right? so it cannot be trusted.

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

0

If the page is refreshed, everything that was stored in memory (all your variables, component states, etc.) is lost. You need to use localStorage to know if the sidebar needs to be opened when the page is loaded and the component is mounted:

useEffect(() => {
  // This runs when the component is mounted (after the page loads).

  if (localStaorage.getItem('openSidebarOnLoad') === 'true') {
    setIsPaneOpen(true);

    localStorage.removeItem('openSidebarOnLoad');
  }
}, []);

const handleButtonClick = () => {
  localStorage.setItem('openSidebarOnLoad', true);

  window.location.reload();
};

<button onClick={ handleButtonClick } className="btn-default">Click me</button>
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