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

165
Views
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
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!