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

245
Visualizações
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
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