Keeping global state inside a singleton
Unanswered
Vojin posted this in #help-forum
VojinOP
Hi, I have a large application in which I need to merge data from components that are on the opposite sides of the dom tree. How would you go about doing this in NextJS, why does industry prefer state management libraries, and why is it a bad idea to keep the state inside a singleton class, which won't cause rerender on all components( maybe force rerender conditionally?)
2 Replies
VojinOP
now thinking about it, isn't that exactly what state managers do, thank you
in a server-rendered context, a singleton would mean you share the same instance for all requests, leaking the data from different pages/users. most state management libraries avoid rerendering components that don't read the value so you don't need to worry about everything rerendering on a single value change