News for hackers. Stuff that matters.
Re:Things I wish I knew about state management when I starte... by shadowgovt on Monday February 10, 2020 @04:31PM (#22293604)
For the specific example the article gives, you probably should implement it by having a top-level component change one of its class identifiers and having the CSS properly select light mode / dark mode all the way down the chain.

... but the purpose of state is to keep track of whether you're in light mode or dark mode. You don't want the arbiter of that knowledge to live on the DOM if you're doing a web app, because you need to reason about who is allowed to change between light and dark mode and the DOM is global state; anything in your app could be editing it. State (among its other uses) serves as a gatekeeper on the ground truth of what mode you're in (and if all changes to presence / absence of the class in question pass through that component state, you're good to go).

There are no comments on this comment yet.