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

113
Visualizações
onClick button to go back to previous page/component React

So I have this div that switch from one component to another by changing the state after clicking on a button.

{ !showForm ? (
     <div className={styles.showTicketContainer}>
          <div className={styles.showTicketBox}>
               //some code for UI
          </div>
          <div className={styles.whitelistBox}>
                <Button className={styles.whiteListToggleButton} shape="round" onClick={() => setShowForm(() => true)}>Whitelist</Button>
          </div>
      </div>
) : (
   <InputEmail />        // render another component within this div after clicking the whitelist button
)}

So to visualize this is from this to this. And I would like to add one button on the email page so that I can go back to the first page.
Do I still use the same way which is:

{ !showForm ? (
      //some UI code
) : ( 
   <someComponent/>
)}

or is there any better way to do this.

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

0

you can use this:

 const history = useHistory();
  history.goBack();
about 4 years ago · Juan Pablo Isaza Relatório

0

If you're creating pages, I definitely suggest using React Router or a similar library to handle this. With React Router, you can easily "back" out to the previous page, and even the "back" button in the user's browser will work, instead of having to click a button.

about 4 years ago · Juan Pablo Isaza Relatório

0

This code will work. Add them wherever required..

import { useHistory } from "react-router-dom";

function demo () {
    let history = useHistory();
    const goToPreviousPath = () => {
        history.goBack()
    }
    return (
      <div>
        <Button
          onClick={goToPreviousPath}
        >
          Back
        </Button>
      </div>
    ):
}
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