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

244
Views
dispatch loadstate action inside of useeffect after page load error

i have cookie based authentication so i need call api to check for authentication on each page load.also i am using redux to maintain a global auth state like below

const initialState = {
  user: {},
  isLoading: false,
  error: null,
  isTeacher: false,
  isModerator: false,
  isStudent: false,
};

on each refresh inside of useeffect of app page

const dispatch = useDispatch();
  useEffect(() => {
    dispatch({ type: "GET_USER" });
  }, []);

this is giving me error. i want to initialize the state on login before the page renders.

const isAuthenticated =
    select.isTeacher || select.isStudent || select.isModerator;
 <Router>
      <div>
        <Routes>
          <Route
            path="/"
            element={!isAuthenticated ? <Landing /> : <Navigate to="/" />}
          />
          <Route
            path="/home"
            element={isAuthenticated ? <Home /> : <Navigate to="/" />}
          ></Route>
          <Route path="*" element={<NotFound />} />
        </Routes>
      </div>
    </Router>

the dispatch call inside of useeffect is giving me error like i cannot use a hook inside of another hook.

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!