|
|
|
|
|
by tootie
3132 days ago
|
|
I think it's mostly react-redux. There's arcane boilerplate in the connect function, mapDispatchToProps looks like a leaky abstraction, actions being passed as objects with a string in them is super brittle. I don't have a fix, but I think just being able to inject a link to the store and then having an API that can be manipulated directly from the component would more comprehensible and cut down on the layers of indirection. I typically see corresponding action, reducer js file for a component when 95% of the logic is already in the component. Just merge them. |
|
It's also worth noting that I personally highly recommend consistently writing separate action creator functions [0], and using the "object shorthand" argument to `connect` instead of writing a separate `mapDispatch` function.
That said, it also seems like part of what you're concerned with is the fundamental design of Redux. The use of plain object actions as a layer of indirection is deliberate [1], and it's what enables capabilities like time-travel debugging. Actions need to be serializable for that to work, and therefore strings are the best solution for the action's `type` field [2].
You certainly don't have to keep _everything_ in Redux. You should consider whether a given bit of state should live in Redux, or in a component's state [3]. But, if you _are_ going to keep data in Redux, then actions and reducers are necessary for the Redux data flow. They don't have to be in separate files [4], but they need to exist to update the store.
[0] http://blog.isquaredsoftware.com/2016/10/idiomatic-redux-why...
[1] http://blog.isquaredsoftware.com/2017/05/idiomatic-redux-tao...
[2] https://redux.js.org/docs/faq/Actions.html#actions-string-co...
[3] https://redux.js.org/docs/faq/OrganizingState.html#organizin...
[4] http://blog.isquaredsoftware.com/2017/05/idiomatic-redux-tao...