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

215
Vistas
TypeError: Cannot read properties of undefined reading 'length'

I'm getting this error within the equipmentExercises block while fetching the data from the API. I have already checked the datatype which is an array. And equipmentExercises.length is showing an undefined datatype.

const SimilarExercises = ({ targetMuscleExercises, equipmentExercises }) => {
    console.log(equipmentExercises);
    return (
        <Box sx={{ mt: { lg: '100px', xs: '0px' } }}>
            <Typography
                sx={{ fontSize: { lg: '44px', xs: '25px' }, ml: '20px' }}
                fontWeight={700}
                color="#000"
                mb="33px"
            >
                Similar <span style={{ color: '#FF2625', textTransform: 'capitalize' }}>Target Muscle</span> exercises
            </Typography>
            <Stack direction="row" sx={{ p: 2, position: 'relative' }}>
                {targetMuscleExercises.length !== 0 ? <HorizontalScrollbar data={targetMuscleExercises} /> : <Loader />}
            </Stack>

            <Typography
                sx={{ fontSize: { lg: '44px', xs: '25px' }, ml: '20px', mt: { lg: '100px', xs: '60px' } }}
                fontWeight={700}
                color="#000"
                mb="33px"
            >
                Similar <span style={{ color: '#FF2625', textTransform: 'capitalize' }}>Equipment</span> exercises
            </Typography>
            <Stack direction="row" sx={{ p: 2, position: 'relative' }}>
                **{equipmentExercises.length !== 0 ? <HorizontalScrollbar data={equipmentExercises} /> : <Loader />}**
            </Stack>
        </Box>
    );
};
about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

This is because your equipmentExercises and targetMuscleExercises might be null at first place.

You can fix this by adding a check like this: equipmentExercises?.length !== 0 or equipmentExercises && equipmentExercises.length !== 0

about 4 years ago · Santiago Trujillo Denunciar

0

You could be passing in a string of an array, instead of an array. Are you able to validate with typeof?

Array and String console.log output look very similar

about 4 years ago · Santiago Trujillo 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