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

136
Visualizações
Unhandled Rejection (TypeError): Cannot read properties of undefined (reading 'error')
const getToken = (userId, token) => {
  22 |   getmeToken(userId, token).then((info) => {
  23 |     console.log("INFO COMING", info);
> 24 |     if (info.error) {
  25 |      setInfo({ ...info, error: info.error });
  26 |     } else {
  27 |       const clientToken = info.clientToken;

What is meant by Unhandled rejection, cannot read properties of undefined??.

I have defined the error and also assigned a value for it, below is the code of useState

  const [info, setInfo] = useState({
    loading: false,
    success: false,
    clientToken: null,
    error:"",
    instance: {},
  });

As per the above code, I have defined and assigned the value for error, then why is the browser still showing cannot read properties of undefined. Can anyone please clarify this?

getmeToken function code is below

export const getmeToken = (userId, token) => {
    return fetch(` ${API}/payent/gettoken/${userId}`, {
        method: "GET",
        headers: {
            Accept: "application/json",
            "Content-Type": "application/json",
            Authorization: `Bearer ${token}`
        }
    }).then(response => {
        return response.json();
    })
    .catch(err => console.log(err))
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

First, check the output of the getmeToken function. Then, you can use info?.error instead of info.error to handle this error.

Edit: Check the ${API}/payent/gettoken/${userId} url again. I think /payent/ is incorrect (/payment/ is correct)

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