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

200
Visualizações
Calling useStore inside functional component but getting error

I want to use store data inside of my async action but when I call the useStore hook I get this error:

Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:

  1. You might have mismatching versions of React and the renderer (such as React DOM)

  2. You might be breaking the Rules of Hooks

  3. You might have more than one copy of React in the same app

     export function getCommitsData() {
       const store = useStore();
       return async function (dispatch: Function) {
         try {
           const commits = await axios.get(`url`);
           const commitsData = await commits.data;
    
           dispatch(getCommitsDataAction({ commitsData }));
         } catch (err) {
           await console.log(err);
         }
       };
     }
    
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You are only allowed to use hooks in

  • function components: functions whose name starts with a capital letter which are only used in JSX (they cannot be called directly), or
  • custom hooks: functions whose name starts with use, and to which the same rules apply.

In particular, you are not allowed to use hooks in action creators, which is what you seem to be doing.

If you are using Redux Thunk, I guess you could use getState instead. Alternatively, you could use the useStore hook inside the component and pass the store to the action creator as an argument.

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