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

147
Views
Can't access prop in another component?

I'm getting myself confused with React here (total newbie). I have a simple component that fetches some data that always returns {"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;

My Graph.js looks like the following:

import { React } from 'react'

export default function Graph({results}) {
  console.log(results)
  return (
      <div>
          <h1>{results}</h1>
      </div>
  )
}

Why doesn't the score render on the page? I've confirmed that the data returns correctly, I just can't seem to access it right.

Here's the console output:

enter image description here

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Results is an array.

<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!