Hacker News new | ask | show | jobs
by chrismaltby 2041 days ago
I can second that, I’ve just recently started migrating my open source application [0] to use Redux Toolkit and the hooks API (+Typescript) and it’s been a pleasure to use and MUCH less boilerplate than the previous implementation. Thanks for your efforts working on this!

[0] https://github.com/chrismaltby/gb-studio/tree/v2beta

1 comments

Nice, glad to hear that!

Yeah, RTK is written in TS and specifically designed for a good TS usage experience with a lot of type inference, and the React-Redux hooks API is _much_ simpler to use with TS since it's really just a matter of declaring the type of `state` in your selectors. (Well, okay, to use thunks in components you gotta supply a customized type for `dispatch` that knows it can accept thunks too.)

FYI, we've got some new RTK APIs in the works that are close to alpha status that I think are really gonna surprise people and make some use cases a _lot_ nicer too. Hoping we can formally announce them here in the next couple weeks.

Lemme glance at that repo you listed there...

Oh wow, that's a really impressive project there, and some neat larger-scale use of RTK! Thanks for linking that.

A few quick bits of feedback on your code since I've got it open:

- A couple of those extra middleware look like they could maybe just be hand-written thunks instead, such as `projectMiddleware`

- for `projectMiddleware` in particular, you probably ought to be doing `storeAPI.dispatch(loadProject))` instead of trying to unwrap the thunk yourself

- strictly speaking, a reference to `window.width` shouldn't be in the reducer itself - the value should be in the action, preferably via the `prepare` callback. (In practice it won't really make a difference, just pointing it out as an FYI.)

- always nice to see actual uses of `undoable()` in the wild :)

I really appreciate you taking the time to code review the Redux store! This is some really great advice that I'll definitely be implementing. The project has definitely been a big learning experience :)

Very much looking forward to these new RTK APIs. Thanks again for your help.