Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

187
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda