Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

253
Vistas
Cannot read properties of undefined (reading 'slice')

I can't figure out the problem with the code as I have even matched it with the source code provided by the git user and it is same, but still showing error So below is the error:- error

Below is the code for shortenAddress component:-

 export const shortenAddress = (address) => `${address.slice(0, 5)}...${address.slice(address.length - 4)}`;

Below is the code of the Welcome component

        <p className="text-white font-light te-xt-sm">{shortenAddress(currentAccount) }</p>

Please,can someone tell the answer to this question of mine...

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The issue is because, when you wont get address then address is undefined and not an array.

What you can do is, check address exists like

export const shortenAddress = (address) => {
  if(address.length) {
    return `${address.slice(0, 5)}...${address.slice(address.length - 4)}`
  }
  return address
}

OR you can also optional chaining ? operator:

export const shortenAddress = (address) => `${address?.slice(0, 5)}...${address?.slice(address.length - 4)}`;

Let me know, if you feel any issue.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda