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

166
Visualizações
Fetch Flask Json data with React (error: 'data' is not defined)

I have a simple Flask backend and I'm trying to fetch json data from it in a simple React frontend. However when I run the React code I get an error: src/App.js Line 8:57: 'data' is not defined no-undef. From the examples I've seen it seems data should be accessible. I'm not trying to do anything complicated with states or effects, I'd like as a first step to be able to simply fetch the Flask json data and print it out in the frontend.

My Flask backend is hello.py:

from flask import Flask
app = Flask("__name__")

@app.route('/hello/')
def hello():
    return {'1': 'hello'}

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8000)

React files. App.js:

import React from 'react';

let url = 'http://localhost:8000/hello

function App() {
    fetch(url).then(res => res.json()).then(console.log(data))

export default App;

index.js:

import React from "react";
import ReactDOM from "react-dom";
import App from "./App";

ReactDOM.render(<App />, document.getElementById("root))
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

As mentioned in my comment you are missing to define the data variable. It's like in the then Block where you access the res. So maybe it works if you write something like:

function App() {
    fetch(url).then(res => res.json()).then(data => console.log(data))
about 4 years ago · Juan Pablo Isaza 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