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

148
Views
¿No puede acceder a prop en otro componente?

Me estoy confundiendo con React aquí (novato total). Tengo un componente simple que obtiene algunos datos que siempre devuelven {"score":100} :

 import React, { useEffect, useState } from "react"; import Graph from "./Graph.js"; const UsingFetch = () => { const [results, setResults] = useState({"score": null}); // initially set score to null const fetchData = () => { fetch("https://myapi.com/id=1") .then((response) => { return response.json(); }) .then((data) => { setResults(data); // update results with integer score }); }; useEffect(() => { fetchData(); }, []); console.log(results) return ( <div> <Graph results={results.score}></Graph> </div> ); }; export default UsingFetch;

Mi Graph.js se parece a lo siguiente:

 import { React } from 'react' export default function Graph({results}) { console.log(results) return ( <div> <h1>{results}</h1> </div> ) }

¿Por qué la partitura no aparece en la página? He confirmado que los datos regresan correctamente, simplemente parece que no puedo acceder a ellos correctamente.

Aquí está la salida de la consola:

ingrese la descripción de la imagen aquí

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Los resultados son una matriz.

 <h1>{results.map((result) => (result.score)}</h1>
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!