Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

167
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda