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

223
Visualizações
Detect page reload on react (the history keeps the url before the reload action)

I'm having some issues with a tab component in multiple instances inside the same page. I would like some sort of page reload detection to be able of clearing the history. This is my prefilter function and click tab function when someone reloads:

const onTabClick = (tabId, tabHead) => {
    const state = !tabSelected;
    toggleTabSelected(tabId);
    history.push(
      `${location.pathname}?tab=${tabId}`,

      {
        shallow: true,
      }
    );
  };


 const preSelect = () => {

    if (values.tab) {
      let queryString = values.tab.toString();
      let selectedTab = Number(queryString) - 1;
      const allTabs = props.tabs;

      toggleTabSelected(queryString);
      toggleMobSelected(queryString);

 
    } else {
     
      toggleTabSelected(firstTab);
      toggleMobSelected(firstTab);
    }
  };

  useEffect(() => {
    preSelect();
  }, [tabSelected, mobSelected]);

The problem with this code is when I reload the page, the history keeps the url of the last tab that was open, while I would like to reset it. Thanks

about 4 years ago · Juan Pablo Isaza
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