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

166
Vistas
ReactJs useEffect execute twice when the page load

UseEffect executes twice when it should execute only once I think. I use useEffect here to fetch some info when the page load, and I need to fetch data only once. I used to do this with the code below, but now I'm facing this problem

import "./App.css";
import axios from "axios";
import { useEffect, useReducer } from "react";

const appInitialState = {
  pageLoading: true,
  adminSignedIn: false,
};
const appStateReducer = (state, action) => {
  if (action.type === "adminSigned") {
    return { ...state, pageLoading: false, adminSignedIn: true };
  } else {
    return { ...state, pageLoading: false, adminSignedIn: false };
  }
};

function App() {
  const [appState, appStateDispatch] = useReducer(
    appStateReducer,
    appInitialState
  );
  useEffect(() => {
    axios.post("http://localhost:8080/admin/v1/isAuthenticated").then((res) => {
      console.log(res.data);
      appStateDispatch({
        type:
          res.data.isAuthenticated === true ? "adminSigned" : "adminNotSigned",
      });
    });
  }, []);

  return (
    <div className="App">
      <h1>App</h1>
    </div>
  );
}

export default App;

about 4 years ago · Juan Pablo Isaza
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