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

175
Views
Error de tipo: this.state.jokes.map

Quiero mostrar una broma de API.

Tengo este error: "TypeError: this.state.jokes.map no es una función"

Mi código:

 import React, { Component } from "react"; import Footer from "../Footer/Footer"; import axios from "axios"; class Content extends Component { constructor(props) { super(props); this.state = { jokes: [], }; } componentDidMount() { axios .get(`https://sv443.net/jokeapi/v2/joke/Programming?type=single`) .then((res) => { const jokes = res.data; this.setState({ jokes }); }); } render() { return ( <div> <div className="content_containeer"> <h1>Full-stack .NET developer</h1> {this.state.jokes.map((e) => ( <p>{e.joke}</p> ))} <Footer /> </div> </div> ); } } export default Content;

Soy un novato en esto y quiero entender por qué se produce este error.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Esta es la respuesta de la URL que obtienes

https://sv443.net/jokeapi/v2/joke/Programming?type=single

 { "error": false, "category": "Programming", "type": "single", "joke": "I have a joke about Stack Overflow, but you would say it's a duplicate.", "flags": { "nsfw": false, "religious": false, "political": false, "racist": false, "sexist": false, "explicit": false }, "safe": true, "id": 301, "lang": "en" }

No es una matriz, es un objeto. .map() solo funciona en una matriz.

Puedes probar este en su lugar: https://v2.jokeapi.dev/joke/Any?amount=5&type=Single

busca res.data.jokes como dicen tus jokes

ejemplo: https://codesandbox.io/s/charming-feather-sd2w8c

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!