Today at work I was solving two infinite loops, both based on having to finesse dependency arrays in useEvent() or useMemo() type things in React.
Hopefully this is less of an unpopular opinion than it was a while back (I think the industry as a whole is more aware of React's limitations) but React's flavor of declarative programming is so damn "jumpy" compared to, say, the jQuery stuff that preceded it. jQuery coding could suck if you weren't sure what was modifying the DOM, but in general the DOM was stable and the methods to change it (often after doing server side rendering, another technology people had to reinvent for some reason) were more or less transparent.
(And hell... when you have React controlling an <input> tag by using state? So that every thing the user types in changes the state, and then React sets the value tag? The ONLY reason the cursor doesn't jump to a default position is because of React's optimizations to recognize it doesn't actually need to rerender that text box. It seems crazy to me that a fundamental UX experience of being able to type anywhere in an input field is dependent on an optimization like that, since cursor position is some kind of hand-wave-y implied state.)
But now with React... like we used to have MVC, Model-View-Controller as a no frills way of doing UI. But React has always mashed together the Controller into the View. And when it's hard to realize you're modifying the Model, aka the state, or accidentally looking at the wrong state to trigger more actions, man, that's just a recipe for infinite loops and rendering that never ends.
Maybe some year the industry will recognize the power of simplicity. Or not, and we'll just hope the AI bots are doing a good job of thinking through the edge cases.
Wednesday, May 28, 2025
feeling loopy
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment