It seems like a crazy idea, but is there any problem if I use globalThis to store the global state of my browser only SPA.
I am thinking of something like this
globalThis.state = {...initialStateData}; // attach a property to globalThis and initialize
//later in any component, mutate the value
globalThis.state.counter = 45;
//yet in some other area, access and display the value
console.log(globalThis.state.counter);
This can be taken further by introducing proxies into the mix and create something like a light weight redux.
I tested this in chrome, and it works (by works I mean chrome had no objection on me attaching my data to globalThis).
My question is, is it a crazy idea and should not be used in a production app because of some standards that I might be violating in ignorance?
Or perhaps, behaviour of globalThis is gonna change over time and browsers will not allow user-attached attributes to this specific object?
EDIT: This question is about pure vanilla JS and not about redux or react or even typescript.
How to define global variable in Deno? will be the closest match to the current query