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

102
Views
Tengo un problema con la obtención de datos con useEffect

aquí está mi código.

 import React from 'react' import { useEffect, useState } from 'react'; import './style.css' function App(){ let api = ("https://free-to-play-games-database.p.rapidapi.com/api/game?id=452", { "method": "GET", "headers": { "x-rapidapi-host": "free-to-play-games-database.p.rapidapi.com", "x-rapidapi-key": "f65083b32emshf3a0f94016a0bb1p159106jsn48481cc9c6ca" } }) useEffect(()=>{ (async function(){ let data = await fetch(api).then(res=>res.json()); console.log(data); })(); },[api]); return( <div>Test</div> ); }; export default App;

este es el error que estoy recibiendo.

 Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0

funciona con otras llamadas de api simples como "https://www.breakingbadapi.com/api/" pero no funciona con esta api que estoy usando, no estoy seguro de por qué.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

let api = ("https://free-to-play-games-database.p.rapidapi.com/api/game?id=452", { "method": "GET", "headers": { "x-rapidapi-host": "free-to-play-games-database.p.rapidapi.com", "x-rapidapi-key": "f65083b32emshf3a0f94016a0bb1p159106jsn48481cc9c6ca" } })

Está utilizando el operador de coma , por lo que api solo contendrá el objeto que está presente después de la URL.

Almacene esto como un objeto o una matriz:

 const api = ["https://free-to-play-games-database.p.rapidapi.com/api/game?id=452", { "method": "GET", "headers": { "x-rapidapi-host": "free-to-play-games-database.p.rapidapi.com", "x-rapidapi-key": "f65083b32emshf3a0f94016a0bb1p159106jsn48481cc9c6ca" } }] function App() { useEffect(() => { (async function () { const [url, options] = api; let data = await fetch(url, options).then(res => res.json()); console.log(data); })(); }, []); // this can be empty as api is outside and doesn't change return ( <div>Test</div> ); };
about 4 years ago · Santiago Trujillo 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!