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

147
Views
How to connect flask rest API output to react and display result

I am doing inference using flask rest API and I got the result

{
result: {
predictions: -3.4333341121673584
} }

bypassing multiple args in the get as the URL I got the above result http://127.0.0.1:3000/predict?solute=CC(C)(C)Br&solvent=CC(C)(C)O Now I want to use this result to use in a react app.

I have written the code below

import { useState, useEffect } from "react";

function App() {
  const [state, setState] = useState({});

  useEffect(() => {
    fetch("api/")
      .then((response) => {
        if (response.status == 200) {
          return response.json();
        }
      })
      .then((data) => console.log(data))
      .then((error) => console.log(error));
  });

I have written the following using a tutorial on the internet. I am new to using fetch API or Axios. Need help to get this result in react app

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

import { useState, useEffect } from "react";

function App() {
  const [data, setData] = useState(null);
  const [loading, setLoading = useState(true);
  const [error, setError] = useState(null);

  useEffect(() => {
    fetch("http://127.0.0.1:3000/predict?solute=CC(C)(C)Br&solvent=CC(C)(C)O")
      .then((response) => {
        if (response.status == 200) {
          return response.json();
        }
      })
      .then(setData)
      .catch(setError)
      .finally(() => setLoading(false));
  }, []);

  if (loading) {
    return <p>Loading</p>
  }

  if (error) {
    return <p>{JSON.stringify(error)}</p>
  }

  return <p>{JSON.stringify(data)}</p>
}
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!