News for hackers. Stuff that matters.
Re:React-copy-write: immutable React state management library by applecrazy on Thursday September 13, 2018 @10:37AM (#17978936)
The main issue is that React needs state passed around as props otherwise, which becomes unweieldy if you didn’t have a global state.

I believe it also makes debugging state issues easier if you have a single source of truth.

Edit: this is somewhat alleviated by the introduction of the React Context API[1], which provides some cleaner functionality but requires quite a few extra components in the render tree.

[1]: https://reactjs.org/docs/context.html

Re:React-copy-write: immutable React state management library by krishanath on Thursday September 13, 2018 @10:41AM (#17978963)
>> state passed around as props

Context provides a way to pass data through the component tree without having to pass props down manually at every level. https://reactjs.org/docs/context.html

>> single source of truth

Often, several components need to reflect the same changing data. We recommend lifting the shared state up to their closest common ancestor. https://reactjs.org/docs/lifting-state-up.html

Re:React-copy-write: immutable React state management library by kabes on Thursday September 13, 2018 @11:34AM (#17979419)
Note that Context is a pretty new API (1), way newer than most state management libraries. Before that it quickly became unmanageable to lift state up and pass props down all the way.

[1] https://github.com/facebook/react/blob/master/CHANGELOG.md#1...

Re:React-copy-write: immutable React state management library by applecrazy on Thursday September 13, 2018 @10:49AM (#17979023)
I guess then I have no idea why Redux is so widely used, given now the Context API exists.
Re:React-copy-write: immutable React state management library by acemarke on Thursday September 13, 2018 @11:48AM (#17979534)
Multiple reasons.

First, Redux has been around since 2015 (and won the "Flux Wars" that had been going on for a year before that), whereas the new `createContext` API only came out a few months ago.

Second, Redux provides a lot more guidance around how you're supposed to structure your application. Context only provides a method for making values available to deeply nested components in the tree.

Third, the Redux ecosystem is huge, with addons available for effectively any use case you can think of. [0]

Please see my post "Redux - Not Dead Yet!" [1] and Dave Ceddia's post "Redux vs the React Context API" [2] for more details on how they relate.

[0] https://blog.isquaredsoftware.com/2017/09/presentation-might...

[1] https://blog.isquaredsoftware.com/2018/03/redux-not-dead-yet...

[2] https://daveceddia.com/context-api-vs-redux/

Re:React-copy-write: immutable React state management library by tptacek on Thursday September 13, 2018 @12:49PM (#17980112)
Redux is overused, because of a meme that suggests that the de facto standard React "stack" is React, Redux, and React-Router. That's just a meme (Dan Abramov even wrote a blog post debunking it!) but some memes are hard to fight.
Re:React-copy-write: immutable React state management library by alexkoeh on Thursday September 13, 2018 @11:10AM (#17979213)
Redux the library is not "state management for react". It's more of a concept that gives you a predictable structure around how state changes over time.

I think what you're thinking of is specifically the `react-redux` library which gave a nice abstraction to the old & clunky React context API. The new context API was released with React 16.3 (which came out March of this year).

Re:React-copy-write: immutable React state management library by mikewhy on Friday September 14, 2018 @10:18AM (#17987341)
The new Context API can't be used in lifecycle methods, which is a bit of a letdown.
Re:React-copy-write: immutable React state management library by beaconstudios on Thursday September 13, 2018 @12:27PM (#17979862)
the new Context API replaces the `connect()`/`<Provider />` functionality, but not the flux data flow model. Nor does it provide a replacement for the surrounding redux ecosystem - so there's still plenty of benefit to using redux.