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

165
Views
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 answers
Answer question

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