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

149
Visualizações
Variable export without function call

I am trying to export a variable that gets updated from state. The challenge I have is that I cannot modify how the variable is being exported, as it is being used in way too many files at the moment.

Maybe can call the function from another file to execute?

import { useAppDispatch, useAppSelector } from "../redux/hooks";
    
export const Content = () => {
  const { store } = useAppSelector((state) => state.StoreReducer);
  return store;
};

export const currency =
  Content() && Content()?.currency ? Content()?.currency : "USD";

export default {
  CURRENCY: currency}

React Error:

Invalid hook call. Hooks can only be called inside of the body of a function component. 
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The error message is clear, react hooks can only be called inside of the body of a function component. But you are calling the Content function in a module scope. You can get the whole state by using store.getState().

import store from '<somewhere>/store';

export const Content = () => {
  const { store } = store.getState().StoreReducer;
  return store;
};

export const currency =
  Content() && Content()?.currency ? Content()?.currency : "USD";

export default { CURRENCY: currency }
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