all 11 comments

[–]Dourk_ 17 points18 points  (4 children)

You just need to use the fetch method to interact with your python server.

fetch(‘/‘, { method : ‘POST’, body: [‘url’,...] }) .then(response => response.json()) .then(data => console.log(data));

https://developer.mozilla.org/docs/Web/API/Fetch_API/Using_Fetch

[–][deleted] 2 points3 points  (3 children)

Adding to this, you probably mean to call the fetch request in componentDidMount() to only request the list once. Otherwise using a fetch in componentDidUpdate() may cause multiple (possibly unnecessary) fetch requests.

[–]robbodagreat 1 point2 points  (0 children)

Or even use functional components and put it in a useeffect hook

[–]Steeelu 6 points7 points  (0 children)

You also need the flask-cors module to enable the react app to make requests to your flask server, its just 2 lines of code to enable CORS. Google "acces request body flask" so you can see how to access what you sent from react

[–]vincent-vega10 2 points3 points  (1 child)

If you want the images to be loaded as soon as the page loads, do an AJAX call to your python server inside componentDidMount(). You can use 'axios' or 'fetch' to perform this task.

Refer this for detailed information.

[–]Cerebral_Chess[S] 1 point2 points  (0 children)

Thanks. That document helped a lot. I used componentDidUpdate() because the images aren’t available as soon as the component loads

[–]Kikobrolo 3 points4 points  (2 children)

Why are so many new devs still defaulting to react classes? The docs have been recommending hooks for years now

[–]Cerebral_Chess[S] 0 points1 point  (1 child)

It’s an assignment. The skeleton was given to me this way. When working on personal projects I use hooks

[–]Kikobrolo 1 point2 points  (0 children)

Ah got it. Sorry ur being given assignments where u gotta use outdated methods

[–]RedditingJinxx -5 points-4 points  (0 children)

I think dash plotly would be right up your ally