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

146
Views
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 answers
Answer question

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 Report
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!