Hacker News new | ask | show | jobs
by sickcodebruh 2377 days ago
I’m mostly with you there but I’ve found saga to be a double-edged sword. The library offers some KILLER features and when you’ve got the right use case, it’s perfect, but it’s so easy to abuse. Because it does so much, I found myself putting more and more responsibilities on it and wound up with some very magical feeling, hard to troubleshoot code.

What changed everything for me was adding GraphQL and getting the majority of my API communication and data storage out of redux. Now, sagas and redux are further down the list of tools I reach for, complexity is way down across the board, and the sagas and reducers that’s remain are more narrowly scoped and easier to reason about and maintain.

2 comments

I'm a Redux maintainer. Sagas are a great power tool, but most apps don't need them [0]. We recommend that most apps stick to thunks as the default [1], and our new official Redux Toolkit package [2] adds thunks automatically to your store setup.

I've used sagas in a couple apps that truly did have very complex async workflows, and they were great for that use case. But yeah, using sagas _just_ for something like data fetching is definitely overkill.

[0] https://redux.js.org/faq/actions#what-async-middleware-shoul...

[1] https://redux.js.org/style-guide/style-guide/#use-thunks-for...

[2] https://redux-toolkit.js.org

As someone that had inherited a redux-thunks project, for me thunks are like calling fetch() directly inside your components callbacks, with extra steps. Really bad for testing and isolating code.

I haven't tried saga, just rxjs with redux which was definitely good. I've also worked with Elm, which supposedly inspired redux. Elm does it perfectly, I don't know why Redux missed async.

> I'm a Redux maintainer. Sagas are a great power tool, but most apps don't need them

I’m super happy that you’re here saying that. I’d go farther than “most apps” to “almost no apps” but, though I’ve mostly worked with apps where I wish they hadn’t used sagas, I have a lot of admiration for the saga concept and library.

> I found myself putting more and more responsibilities on it and wound up with some very magical feeling, hard to troubleshoot code

Agreed. There's a simplicity to React / Redux that I absolutely adore. There's very little magic going on: things happen because you've explicitly told them to. Side-effects in Redux seem to throw this out the window.