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

189
Vistas
convert const values to API calls in React

The following sample data will be coming from backend API call. The backend is flask and the API is already in place at the backend.

const rows = [
  {
    name: "XYZ",
    age: "12",
    email: "xyz@gmail.com"

  },
  {
    name: "David",
    age: "13",
    email: "David@gmail.com"

  },
  {
    name: "abc",
    age: "12",
    email: "abc@gmail.com"
  }
]

How can I integrate the backend API with React? I'm new to react, so I don't know how should I proceed.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

In React you'll have to use two hooks - useState and useEffect. The first one will help you keep the data so you can use it and the second one will help you getting it.

function Component() {
  const [data, setData] = useState(null);

  useEffect(() => {
    fetch('your endpoint here').then(res => {
      if (res.status === 200) {
        return res.json();
      } else {
        // handle error
      }
    }).then(data => {
      setData(data);
    }).catch(err => {
      // handle error
    })
  }, []);

  if (data !== null) {
    return <p>Data is here {data.length}</p>;
  }

  return <p>Loading the data</p>;
}

And just to clarify that we need to use useEffect so we fire the request only once when the component is mounted. This is the effect of using [] for the dependencies' list as a second argument to the hook.

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can use axios for sending api requests.

const [state,setState] = useState()

useEffect(()=>{
  axios.get(url)
     .then(res=>setState(res.data))
     .catch(err=>console.log(err))
},[])
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