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

623
Vistas
Array.prototype.map() expects a return value from arrow function - Apollo client -Reactjs

I am building a project management application using reactjs and graphql.

When I send out query from reactjs it gets a response with the data below

{
   "data":{
    "clients":[
       {
         "name":"Okoye Ifeoma",
         "email":"ify@mail.com",
         "phone":"0805-854-754-580"
       }
    ]
  }
}

But it does not show the data on the browser instead it display the following error on the console

Error: Array.prototype.map() expects a return value from arrow function

Clients

import { gql, useQuery } from "@apollo/client";
import ClientRow from "./ClientRow";
const GET_CLIENTS = gql`
  query getClients {
    clients {
      id
      name
      email
      phone
    }
  }
`;

export const Clients = () => {
  const { loading, error, data } = useQuery(GET_CLIENTS);

  if (loading) return <p>loading...</p>
  console.log(data.clients);
  if (error) return <p>Something went wrong</p>
  return (
    <>
      {!loading && !error && (
        <table className="table table-hover mt-3">
          <thead>
            <tr>
              <th>Name</th>
              <th>Email</th>
              <th>Phone</th>
              <th></th>
            </tr>
          </thead>
          <tbody>
            {data.clients.map(client => {
              <ClientRow key={client.id} client={client} />
            })}
          </tbody>
        </table>
      )}
    </>
  );
};

ClientRow

import { FaTrash } from "react-icons/fa";
export default function ClientRow({ client }) {
  return (
    <tr>
      <td>{client.name}</td>
      <td>{client.email}</td>
      <td>{client.phone}</td>
      <td>
        <button className="btn btn-danger">{FaTrash}</button>
      </td>
    </tr>
  );
}
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

What's gone wrong?

The arrow function in Clients > tbody is not returning anything.

{
  data.clients.map(
    client => { <ClientRow key={client.id} client={client} /> }
  )
}

When you enclose the body of an arrow function in {}s you must expressly return a value.

The Fix

Simply enclose your JSX in parenthesis and return it from the function.

{
  data.clients.map(
    client => { return (
      <ClientRow key={client.id} client={client} /> 
    )}
  )
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

I'm not interested in graphql, but you can check if data is fetched or not.

data && data.clients.map(client => {.....})
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