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

170
Visualizações
I am facing an error of "TypeError: Cannot read properties of undefined (reading 'push')"

I have been facing this issue while using history.push('/pathname') in app.js component. my requirement is that I have to use this history.push inside an onclick handler defined in app.js component which is then sent to button component in via props. I am not able to figure out the solution of this error. (The button component is AppointmentNextBtn). Please guide me.

import { useHistory } from "react-router-dom";
function App(){
  const history = useHistory();
  const onClickNextDateHandler = () => {
history.push("/selectlocation/appointment/selectdate");
console.log("date button runs");
setNextBtnState("time");

};

return(
<Route exact path="/selectlocation/appointment">
        <Toappointmentcontainer
          postAppointmentRequest={postRequestAppointment}
        />
        <div className="btnwidget">
          <AppointmentNextBtn
            onClickDateHandler={onClickNextDateHandler}
            displayState={nextBtnState}
            text="Next"
            button="button"
          />
        </div>
      </Route>

)

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

0

You cannot use history in the same file you declare your route. History objects will always be unavailable in this case. Best way is to do directly it in appointmentNextBtn.

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