3 ms·
Is setState() that bad? If you want the magic of vue’s reactive state, you can just use Proxy which is what it does under the hood. Not sure why React hasn’t st
by jacobsimon 4y ago
Is setState() that bad? If you want the magic of vue’s reactive state, you can just use Proxy which is what it does under the hood. Not sure why React hasn’t standardized that but /shrug
- hbrn 4y agoBecause Proxy wasn't supported when React was designed. I bet if they were to design it a year later, they would go with Proxy. But it wasn't an option at the time, Proxy is not something you can polyfill. Now, the community doesn't know about that. So when you tell them that there's a better way to deal with component state, they immediately get defensive: "No, setState() is way better, there's no magic, it's very explicit". But setState() was a necessary evil, not a genius invention. They made it super-explicit because it was the only way they could do it. Not because of some great foresight. Is it bad? Probably not. I bet it's tolerable. But why settle for less when there are better alternatives?
- addicted 4y agoThis is ahistorical. Proxies have been around for at least a decade (here’s a 2010 talk about it https://youtu.be/sClk6aB_CPk https://youtu.be/sClk6aB_CPk ) React hooks have been around for less than half the time as that. Proxies for setState would be a terrible idea in React for the simple reason that non state variables also exist in React functional components and have dramatically different behavior than state variables. Proxies would make them both look basically the same after initialization which would lead to a ton of bugs as devs lost track of which variable was a state variable and which one wasn’t.
- hbrn 4y agoI don't think you're arguing in good faith. > Proxies have been around for at least a decade Having Proxy described in ES5 standard and having it supported in browsers is two different things. IE market share at that time was around 30-40%. > non state variables also exist in React functional components and have dramatically different behavior than state variables Stateful functional components were introduced in 2018 (React 16). I'm talking about 2011-2013.