4 ms·
Refactored a web app with traditional Redux logic to use Redux Toolkit and it really does make the logic much more pleasurable to read and maintain. I wasn't in
by Drew_ 5y ago
Refactored a web app with traditional Redux logic to use Redux Toolkit and it really does make the logic much more pleasurable to read and maintain. I wasn't in love with the createAsyncThunk + builder.addCase pattern but it worked well enough in practice and isn't very hard to follow.
- acemarke 5y agoAnything particular you didn't like about that? FWIW we'd _like_ to add the ability to define thunks inside of `createSlice`, but there's TS type circularity issues we've been unable to solve, so that's kept us from making it work right. Also, I'd be curious to see if RTK Query can handle your data fetching use cases.
- Drew_ 5y agoIt was indeed the need to define the thunks outside of the slice that irked me, but with multiple thunks for a slice, I just wrote them as part of their own module.
- steve_adams_86 5y agoI’ve been running into circularity bugs lately as well… I think. It’s incredibly hard to tell if you’re doing something dumb or it’s a legitimate bug. Do you know of an issue that’s tracking a specific bug related to the circularity issue you’re seeing in createSlice?
- acemarke 5y agoNot specifically. The general problem we were running into is: - We recommend inferring `type RootState = ReturnType<typeof store.getState>` - That type comes from the slice reducers - Thunks need a `State` type passed in so they know what `getState` returns - But if you do that _inside_ of `createSlice`, TS can't know that `RootState` type yet, because we haven't constructed the slice reducer yet Here was the PR where we tried to come up with something: https://github.com/reduxjs/redux-toolkit/pull/637 https://github.com/reduxjs/redux-toolkit/pull/637 If you're seeing some other issue problem related to RTK, please go ahead and file an issue.
- steve_adams_86 5y agoSorry, I should have specified that it’s in work unrelated to RTK. I was just curious if the bugs we encounter are the same ones. Unfortunately the circularity issues that are closely tracked in the TypeScript repo don’t seem to be making much progress, and in some cases, it seems like TS is fundamentally incapable of working with circular references in some contexts. Like I was saying though, I find it hard to tell at times if I’m running into real limitations of the type system or I’m short a few IQ points, haha.