I read somewhere that you can use a singleton style object, set it's value and then import it elsewhere and the value will remain. For example:
storage-util.js
const storage = {};
export default storage;
App.js
function App() {
useEffect(() => {
storage.token = "1234";
console.log('set token');
});
return (
<div>
<NavbarDefault />
<MainSwitch />
</div>
);
Pricing.js
const Pricing = () => {
useEffect(() => {
console.log(storage.token);
});
return (
<h1 className="heading-text font-weight-bold text-center">
Pricing
</h1>
);
};
However I am getting undefined when trying to access storage.token in Pricing.js, what am I doing wrong here?