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

204
Vistas
TypeError: users.map is not a function

I was working on a react project which is using map function, i am using react router dom and redux also this error is struck when i fetch users from the mongoose database,the file which throws error is Users.js, and my frames collapse, the code is given below Users.js

import React, { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { fetchUsers } from '../../redux/actions/users/userActions';
import Loading from '../Loading/Loading';

const Users = () => {
  const dispatch = useDispatch();
  useEffect(() => {
    dispatch(fetchUsers());
  }, [dispatch]);
  const usersList = useSelector(state => state.usersList);
  const { loading, users, error } = usersList;

  console.log(users, loading, error);
  return (
    <div className='container-fluid'>
      <h1 className='text-center m-5'>List of users {users && users.length}</h1>
      <hr className='text-white' />
      <div className='row text-center justify-content-center'>
        {loading ? (
          <Loading />
        ) : (
          <>
            {users &&
              users.map(user => (
                <div className='col-lg-3' key={user._id}>
                  <div className='card'>
                    <div className='card-body'>
                      <h5 className='card-title'>{user.name}</h5>
                      <p className='card-text'>{user.email}</p>
                      <i className='far fa-address-card h2 text-info'></i>
                    </div>
                  </div>
                </div>
              ))}
          </>
        )}
      </div>
    </div>
  );
};

export default Users;

but while submitting response i am getting the following error

  20 | {loading ? (
  21 |   <Loading />
  22 | ) : (
> 23 |   <>
     | ^  24 |     {users &&
  25 |       users.map(user => (
  26 |         <div className='col-lg-3' key={user._id}>

can anyone help me sorting this?

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

0

Check your users object. May be its default value is defined but not with empty array (and you try to use map function), or users in selector have different (non-array) type after setting from server response.

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