Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

624
Views
Array.prototype.map() espera un valor de retorno de la función de flecha - Cliente Apollo -Reactjs

Estoy creando una aplicación de gestión de proyectos usando reactjs y graphql.

Cuando envío una consulta desde reactjs, obtiene una respuesta con los datos a continuación

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

Pero no muestra los datos en el navegador, sino que muestra el siguiente error en la consola

Error: Array.prototype.map() espera un valor de retorno de la función de flecha

Clientela

 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> )} </> ); };

FilaCliente

 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 answers
Answer question

0

¿Qué salió mal?

La función de flecha en Clientes > tbody no devuelve nada.

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

Cuando encierra el cuerpo de una función de flecha en {}s, debe return expresamente un valor.

La solución

Simplemente encierre su JSX entre paréntesis y devuélvalo desde la función.

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

0

No estoy interesado en graphql, pero puede verificar si los datos se obtienen o no.

 data && data.clients.map(client => {.....})
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!