Nicky Christensen’s Post

Do you also see state living 𝟯 𝗼𝗿 𝟰 𝗹𝗲𝘃𝗲𝗹𝘀 𝗮𝗯𝗼𝘃𝗲 𝘁𝗵𝗲 𝗰𝗼𝗺𝗽𝗼𝗻𝗲𝗻𝘁 𝘁𝗵𝗮𝘁 𝗮𝗰𝘁𝘂𝗮𝗹𝗹𝘆 𝘂𝘀𝗲𝘀 𝗶𝘁? A modal. A dropdown. A simple toggle. And to understand its behavior, you have to trace through a page, a layout, a section, and a container. We did that because we were taught to lift state up. And the reasoning is solid, i wont argue against this... But "lift state up when needed" and "lift state up by default" are not the same rule. One is a tool. The other is a habit. When state lives far from the thing it controls, the component stops being self-contained. You can't open it and understand it. You have to go hunting. We call that component "controlled." Sometimes it just feels remote-controlled. Three files away from the thing it's supposed to explain. I still lift state when two components genuinely need to coordinate. That's exactly what it's for. But a toggle that only one component cares about? That state belongs next to that component. Not because it's more clever. Because code you can understand in isolation is code you can trust. Where do you draw the line between lifting state and keeping it local? #frontend #javascript #react #vue #svelte

To view or add a comment, sign in

Explore content categories