News for hackers. Stuff that matters.
Re:Redux – Not Dead Yet (2018) by vikingcaffiene on Thursday April 09, 2020 @11:17AM (#22823348)
I love Redux but I am very frugal about what I put into the store and have come up with a strong set of design patterns with my team to know what should and should not go there. That, in conjunction with hooks for any other stateful concerns we have, makes for a sane and pleasant dev experience.

IMO the biggest and best draw of Redux is how it allows you to completely separate your business logic from your UI layers. Your components only know about props and state and are rather trivial to test. Hooks are great for re-usable logic as well but my team made the choice to have hooks deal only with localized state concerns and have a robust Actions => Services => Reducer layer for everything that speaks to things outside that constraint. Its worked out wonderfully so far. Tests are a breeze and logic is highly portable. Our UI layer is thin and easy to change.

Its not all roses of course. The Redux store can turn into a rats nest of keys and values with no obvious structure (or worse, duplicated structures). It's something that requires actually sitting down and modelling out your data structures. Sadly that's something I don't see very often (and I am just as guilty as anyone else). The Redux team came up with some good guidelines on this point (too lazy to track the link down but its on the main site) and I think they have some really good ideas. I think more than anything its important to consider your store in the same manner you would a database and approach it with that kind of mindset. As with all things JS, its easy to dive in, hard to untangle yourself! :)

Re:Redux – Not Dead Yet (2018) by bugeats on Thursday April 09, 2020 @01:11PM (#22824775)
> I think more than anything its important to consider your store in the same manner you would a database

Yes and to keep it normalized. IMO, Redux is incomplete without some sort of selector layer, which acts as the metaphorical database views.

https://github.com/reduxjs/reselect

Re:Redux – Not Dead Yet (2018) by acemarke on Thursday April 09, 2020 @02:57PM (#22825949)
We've recommended normalizing data as a pattern for years [0], but never had any official tooling to support that use case. Redux Toolkit 1.3 now has a new `createEntityAdapter` API that can help with the process of inserting and updating normalized data [1].

[0] https://redux.js.org/recipes/structuring-reducers/normalizin...

[1] https://redux-toolkit.js.org/api/createEntityAdapter

Re:Redux – Not Dead Yet (2018) by tracker1 on Thursday April 09, 2020 @12:06PM (#22823859)
I do kind of violate this... I tend to use action creators that will accept an event from a component, and use e.target.dataset.someValue as necessary... it's not exactly a violation... but it's muddy... having clean action handler syntax in my Components though it better imho.

I use createActionsHook below in every actions.js file... combined with thunks, it's awesome imho.

https://www.npmjs.com/package/react-redux-actions-hook

Re:Redux – Not Dead Yet (2018) by vikingcaffiene on Thursday April 09, 2020 @12:47PM (#22824464)
Thanks for the perspective. :)

IMO the only downside to your approach is that it couples your action creators to the calling component. That isn't necessarily a bad thing but it all depends on what your particular goals are. If you intend to have your action creators as a kind of "super prop" that is specific to your caller and disposable and single purpose in nature, I think that works. To be successful (again IMHO) you'd want to segregate your business logic outside of that layer into either the reducer (as the redux team recommends) or in a service layer that the actions can talk to (my preferred approach). As always YMMV.

Re:Redux – Not Dead Yet (2018) by tracker1 on Thursday April 09, 2020 @02:02PM (#22825389)
Oh, the results are handled by the reducer... it's not that far off.. expecting an event with a given shape, as opposed to a direct argument. Can even be split, one for the view specifically another for the more pure actioncreator... with the thunks+async function, it's easy to have a start, await api call and finish/error events dispatched.
Re:Redux – Not Dead Yet (2018) by vikingcaffiene on Thursday April 09, 2020 @02:38PM (#22825757)
Yep! :) Sounds like you've thought it through and I see your point.
Re:Redux – Not Dead Yet (2018) by acemarke on Thursday April 09, 2020 @11:37AM (#22823572)
That would be the "Style Guide" docs page:

https://redux.js.org/style-guide/style-guide

Re:Redux – Not Dead Yet (2018) by vikingcaffiene on Thursday April 09, 2020 @02:39PM (#22825760)
Thank you kind stranger :)