6 ms·
React is a tool for managing state. The UI component is somewhat secondary.
by debacle 2y ago
React is a tool for managing state. The UI component is somewhat secondary.
- throwadobe 2y agoReact is one tool for managing state. Still doesn't answer why
- shadowgovt 2y agoIt's a good tool for managing state, especially state that, well, reacts to messages about changes in shared state.
- recursive 2y agoIn react's model, all state is owned by a particular component instance. Most react devs opt for a 3rd party tool for shared state. I would not say that react is good at this.
- bluefirebrand 2y agoThis hasn't really been true for a while, most React projects that I encounter nowadays don't opt for things like Redux or MobX, they just use React Contexts. Which isn't a third party thing anymore
- recursive 2y agoWhen context first came out, there was a buzz about it was going to obsolete Redux. Then it was actually "no it's not". I haven't followed it much since then. I haven't seen a code base that used a context for shared state that could be updated from descendant nodes. But I guess it pretty much has to be an improvement over redux. Still though, the boilerplate required to do it doesn't make it seem like React is particularly good at it, even though it's technically capable.
- shadowgovt 2y ago> I haven't seen a code base that used a context for shared state that could be updated from descendant nodes. I use this pattern commonly. You put a state-update callback into the context. It's my favorite go-to when I don't want to bother writing all that Redux boilerplate (state description plus accessors plus reducers feels... Half-baked).
- acemarke 2y agoNote that Redux usage patterns have changed significantly since 2019. Modern Redux with our official Redux Toolkit package is drastically simpler and easier to use than the original legacy hand-written patterns: - https://redux.js.org/tutorials/essentials/part-2-app-structure https://redux.js.org/tutorials/essentials/part-2-app-structu... - https://redux.js.org/introduction/why-rtk-is-redux-today https://redux.js.org/introduction/why-rtk-is-redux-today
- acemarke 2y agoHi, I'm a Redux maintainer. Context is not an "improvement" over Redux, because they are different tools with different purposes. (This is the primary misunderstanding people have when they try to compare Context and Redux.) Context is a Dependency Injection tool for a single value, used to avoid prop drilling. Redux is a tool for predictable global state management, with the state stored outside React. Note that Context itself isn't the "store", or "managing" anything - it's just a conduit for whatever state you are managing, or whatever other value you're passing through it (event emitter, etc). I wrote an extensive article specifically to answer this frequently asked question, including details about what the differences are between Context and Redux, and when to consider using either of them - I'd recommend reading through this: - https://blog.isquaredsoftware.com/2021/01/context-redux-differences/ https://blog.isquaredsoftware.com/2021/01/context-redux-diff...
- recursive 2y agoThanks for the info. I'd say you're speaking from some position of authority about what redux is and isn't. And to some degree, what react context is and isn't. I vaguely recall seeing this blog post before, maybe. So redux is for "managing and updating" shared state. And context is for "sharing values". All this seems to suggest that react actually isn't that good at shared state, at least when it can change.
- ajkjk 2y agoThat's backwards. React is a tool for writing declarative UI (or declarative anything really) that can handle state updates. Probably they're using it because it's the best tool around for that job.
- afiori 2y agoReact manages the state of the UI, all the props and the virtual DOM counts as state. The declarative part is that the UI is recomputed from the state sorta-ex-novo at each update
- ajkjk 2y agoSure but the essence of it, the reason that it works, is that it shims a declarative architecture into JS. It works because it turns out UI programming works better in a declarative style.The fact that that involves managing state is secondary. I expect that in fifty years all programming will look declarative, either like HTML (which is sorta 'natively declarative') or more like React (which shims it into an imperative language).
- afiori 2y agoState management is not secondary, it is how it can implement the declarative UI with declarative updates.
- ajkjk 2y agoThat is a silly way to phrase it. It's secondary in the sense that of course a UI framework has to manage state. They all do that if they're complex at all. The state management is not what distinguishes React from other frameworks; it is distinguished by the (pseudo-)declarative API that it presents to the programmer.
- DonHopkins 2y agoNew Shimmer is a Floor Wax AND a Desert Topping! https://www.tiktok.com/@user2571420815968/video/7205011129590926634?lang=en https://www.tiktok.com/@user2571420815968/video/720501112959... But both the JavaScript and Lua versions of React are full of high fructose corn syrup, anyway. https://www.youtube.com/watch?v=H_zsZMn5Efk https://www.youtube.com/watch?v=H_zsZMn5Efk I'd prefer a low-calorie high-performance port of Svelte to Lua. https://www.youtube.com/watch?v=T6EVgwMfzb0 https://www.youtube.com/watch?v=T6EVgwMfzb0
- shepherdjerred 2y agoHow did you come to this conclusion?