DEV Community 👩‍💻👨‍💻

Discussion on: Real-time app using React, Redux, Tailwind CSS & Firebase - Part 3

mliakos profile image
Emmanouil Liakos Author • Edited on

I am using "single slice files", like you are mentioning, in a medium-sized app and they are not aging very well. Having state, actions, reducers and selectors, all in a single file does not scale well. Especially when following the "ducks" folder structure, a single feature can very well have 50 action types, 50 reducers and 30 selectors, for example. That could mean an over 1000 line file. Nobody wants to work with that. I think that following the single-file approach is better suited to something like RTK, where you omit creating action types.

Splitting those in separate files and exporting them from a single index.js file seems the way to go, IMHO. Of course there are mistakes and I don't claim that my approach is perfect. There are many (mainly structural) changes I want to make.

However, the code was written one year ago, I am glad that I made mistakes that I can now acknowledge. That's why I plan to refactor and post updates, but this is something I don't have the time to do right now. Moreover, I like to be able to see my progress. I am certainly going to put a warning note, though!

Thread Thread
phryneas profile image
Lenz Weber

That kinda sounds like you are really overusing that. Are those real "business logic" reducers or is that just api interaction stuff?

Thread Thread
mliakos profile image
Emmanouil Liakos Author

Regular "thick" reducers. All API related stuff lives in thunks. It's just a very big module using vanilla Redux.

In an Electron application, where I am using RTK, it scales really well. I think that you have made a great job both in writing the docs for Redux and RTK & in the RTK development itself, it saves from a lot of hassle.

The point I am stretching here is that in order to appreciate and understand RTK or any other abstraction, you have to get your hands dirty first. Keep up the good work 😊