Hacker News new | ask | show | jobs
by wallawe 2722 days ago
Can you point to any writeups on this? Would love to reduce the boilerplate a bit, while still needing a global state management tool for a smaller app.
2 comments

Hi, I'm a Redux maintainer. Here's a few resources.

First, the docs already have a page called "Reducing Boilerplate", which shows patterns like writing a function that accepts a lookup table of reducers [0].

Second, a while back I wrote a pair of posts called "The Tao of Redux" [1] [2]. Part 1 discusses the implementation and intent behind how Redux is meant to be used, and Part 2 looks at why common usage practices exist. As part of that, I pointed out that you can use whatever logic you want in your reducers, and as much or as little abstraction on top of Redux. Switch statements are simply the most obvious way to handle multiple values for a single field, but you should feel free to use whatever approach you want.

Third, we've recently created a new package called `redux-starter-kit` [3]. It helps simplify several common use cases, including store setup, defining reducers, immutable update logic, and even creating entire "slices" of state at once without writing any action types or action creators by hand. I'd encourage you to try it out and let us know how well it works for you.

Please let me know if you've got any other questions I can help with!

[0] https://redux.js.org/recipes/reducing-boilerplate

[1] https://blog.isquaredsoftware.com/2017/05/idiomatic-redux-ta...

[2] https://blog.isquaredsoftware.com/2017/05/idiomatic-redux-ta...

[3] https://redux-starter-kit.js.org/

This is great, thanks so much
Hi, if you mean how to get rid of switch statements, you can check my comment bellow - about "action-reducer".

I've seen https://github.com/erikras/ducks-modular-redux and it's close to what I do.

Also you can check - https://github.com/reduxjs/redux/issues/1167#issuecomment-38...

Thanks so much, I love the pattern in the second link you shared