4 ms·
I said this in another comment, but similarly to this, check out Redux Toolkit (https://redux-toolkit.js.org https://redux-toolkit.js.org), the `slices` feature
by cercatrova 6y ago
I said this in another comment, but similarly to this, check out Redux Toolkit (https://redux-toolkit.js.org https://redux-toolkit.js.org), the `slices` feature changed my view on Redux entirely. Basically you can have a per-feature slice of functionality rather than having actions, reducers, and constants spread around your code. It's analogous to what hooks did, encapsulating similar functionality.
- odensc 6y agoThis is similar to how I've always implemented Redux before using some of my own utilities, but it's nice they have an "official" way to do it now. Does it work well with TypeScript?
- cercatrova 6y agoIt does indeed. If you check out the advanced tutorial on the site you'll see it's in TypeScript.
- acemarke 6y agoYep, RTK is specifically written in TypeScript, and I have a co-maintainer (Lenz Weber) who has done an amazing job working on the TS typedefs to make sure it works well. See the "Usage with TypeScript" docs page: https://redux-toolkit.js.org/usage/usage-with-typescript https://redux-toolkit.js.org/usage/usage-with-typescript
- odensc 6y agoThat's great!
- danlugo92 6y agoIt gets messy once you want to do anything advanced. And even when slices depend on each other (circular dependencies will arise).
- acemarke 6y agoCan you clarify what you mean by "messy" and "advanced"? Circular dependencies are indeed a potential issue, but most people are unlikely to run into that, and we talk about ways to handle that in the docs: https://redux-toolkit.js.org/usage/usage-guide#exporting-and-using-slices https://redux-toolkit.js.org/usage/usage-guide#exporting-and...
- acemarke 6y agoGreat, glad to hear RTK is working well for you!
- mdtusz 6y agoRTK is great! The only thing I wish was a bit different is the `createAsyncThunk` function. It feels dirty providing the action-type string manually, when for all the other actions, this is essentially invisible.
- acemarke 6y agoThe idea of having some kind of special syntax in `createSlice` to support declaring thunks has definitely been suggested, and there's other libraries out there that do similar things. But, anything we add to our API has to be supported indefinitely. Because of that, I wanted to release `createAsyncThunk` and `createEntityAdapter` as "standalone" utilities first and see how they actually get used by the community. I'm definitely open to potentially integrating them together down the road, but I'd rather take it one step at a time and make sure that we're really solving the right problems the right way. If you do have any further feedback on RTK, please feel free to file issues for discussion!