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.
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 }