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

121
Vistas
Reactjs functional compontent call api twice

I just created a simple component in ReactJs and call an api with axios but I noticed in browser network tab that my api called twice in first render, also I tested with a console log, it return twice too! why? I googled and people said this is normal in functional component and normal behavior but I don't want request to api twice! any idea?

import React, { useEffect, useState } from "react";

export default function User() {
  useEffect(() => {
    getUser().then(); // it call api twice, I got data twice!
    console.log(111); // return twice
  }, []);

  const getUser = async () => {
    const user = await Api.Get("User");

    if (user.status === 200) {
      console.log(user);
    }
  };

  return (
    <>
      <div>Hello</div>
    </>
  );
}

Here I use user compontent: Router.js

<BrowserRouter basename="/">
<Routes>
     <Route exact path='/user' element={<User/>}></Route>
</Routes>
</BrowserRouter>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

React 18 introduces a new development-only check to Strict Mode. This check automatically unmounts and remounts the component, making the useEffect hook fire twice on the initial mount.

More there:

https://levelup.gitconnected.com/react-18-the-trickiness-of-useeffect-fadfa65fa4b4

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