Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

150
Visualizações
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 Respostas
Responde à pergunta

0

Results is an array.

<h1>{results.map((result) => (result.score)}</h1>
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda