4 ms·
> in practice people shove all their business logic in there, mostly because React makes it incredibly hard to do anything else. I'm not an expert by any means
by AlexCoventry 8y ago
> in practice people shove all their business logic in there, mostly because React makes it incredibly hard to do anything else.
I'm not an expert by any means, but I wrote a fairly substantial react app recently, and I found that redux not only made this straightforward, but made it hard to do anything else. I did have to learn redux and redux- saga on top of react, but it wasn't hard.
- Aeolun 8y agoJust a FUCK-TON of boilerplate :P
- AlexCoventry 8y agoYou say boilerplate, I say simple declarative layout of the boundaries between UI, state and state transitions. :-)
- acemarke 8y agoPeople use the word "boilerplate" a lot, but everyone seems to have something different in mind when they say it. What specific concerns do _you_ have? I'm a Redux maintainer, and I'm always happy to try to help offer possible solutions.
- Aeolun 8y agoI don’t really think there is a way around it if you go with the action/reducer/saga model. I enjoy my code fairly explicit, so writing a button click that invokes some request has me writing: - A click handler - 3 new action name consts (request, success, failure) - An action instantiation function that takes the necessary arguments for request. - A saga function that catches these request actions, runs a request, and invokes the success action/failure action depending - 3 handlers in my reducers. One for every action. It all adds up if you have a ton of buttons :P
- sdegutis 8y agoThis is exactly the thing we need fixed. I get that Angular has one way of doing it, but I still feel like it's going in the wrong direction (too Java-like).
- acemarke 8y agoSagas are a great power tool, but I personally wouldn't use them for most simple API requests, largely because of the need for "signal actions" to trigger the logic. You might want to check out our new `redux-starter-kit` package [0], which can simplify some common use cases for things like action creators and reducers. There's also many other existing libraries to handle repetitive code like API requests as well [1]. [0] https://github.com/reduxjs/redux-starter-kit https://github.com/reduxjs/redux-starter-kit [1] https://github.com/markerikson/redux-ecosystem-links/blob/master/action-reducer-generators.md https://github.com/markerikson/redux-ecosystem-links/blob/ma... , https://github.com/markerikson/redux-ecosystem-links/blob/master/entity-collection-management.md https://github.com/markerikson/redux-ecosystem-links/blob/ma...
- Aeolun 8y agoI think you need to use sagas for either all your logic, or none of it. Having it half/half just means you’re always searching for where something is located. That said, thanks for the recommendations! I’ll check them out.
- acemarke 8y agoFWIW, I use sagas _and_ thunks in my own app, depending on what it is I need to do. Also related, the new Redux FAQ entry on choosing between async middlewares: https://redux.js.org/faq/actions#what-async-middleware-should-i-use-how-do-you-decide-between-thunks-sagas-observables-or-something-else https://redux.js.org/faq/actions#what-async-middleware-shoul...