DEV Community

Discussion on: Getting started with state management using Redux Toolkit

Collapse
 
markerikson profile image
Mark Erikson

Hi, I'm a Redux maintainer. Very nice post!

Note that Redux Toolkit is orthogonal to React-Redux, and RTK has no UI-related APIs at all. You can have hand-written Redux logic with React-Redux hooks, RTK with React-Redux connect, or any combination thereof. (In fact, since RTK is its own independent lib, you can even use it without a Redux store to generate reducers for useReducer, or by using Redux as the state management layer for another framework like Angular.)

Redux Toolkit is a wrapper around the Redux core, both in terms of actual API usage (configureStore > createStore), and conceptually. You still have to understand "dispatching actions", "reducers", "immutability", etc. Given that Redux has been around for several years, and there's millions of lines of Redux code out there already, we couldn't just shove these APIs into the Redux core.

That said, we are officially recommending RTK as the default way to write Redux logic. Also, I'm currently working on a rewrite of the Redux core docs, and as part of that I'm working on a new "Quick Start" tutorial for the Redux docs that teaches Redux at a higher level ("do this", not "how/why it works"), and teaches RTK and the React-Redux hooks API as the default. It's not done yet, but I'm hoping to tackle the last section of the first draft shortly:

deploy-preview-3740--redux-docs.ne...

For some more background on how and why we came up with RTK and what the intent is, see:

Collapse
 
emma profile image
Emma Goto 🍙

Thanks for the comment! The new docs look good - will you be rewriting the basic/advanced tutorials into using the toolkit too?

I also really like that style guide / recommendations page you've linked - lots of useful tips in there.

Collapse
 
markerikson profile image
Mark Erikson

The current "Basic/Advanced" tutorial sequence tries to teach Redux "from the bottom up", ie, here's all the concepts, here's how everything works, here's how to do everything "by hand". We still need to have that kind of a tutorial so that people understand what's actually going on inside.

My plan is to have both the "Quick Start" tutorial as the main way to get going, and an updated version of the "Basic/Advanced" sequence that teaches how it all works. The updated bottom-up sequence will remove outdated references and terms (like "If you've ever written a Flux app, you'll feel right at home"), show simpler patterns (inlined action types with a naming convention like {type: "todos/todoAdded"} instead of const ADD_TODO = "ADD_TODO", putting logic for a feature in a single file instead of splitting across multiple files), and probably redo the example apps. Then, at the end of that sequence, we'll point out that RTK does all this work for you already and you should use RTK instead of doing it all by hand.

You can see my plans for reworking the docs overall in github.com/reduxjs/redux/issues/3592 .

And thanks! I did write the Style Guide page several months ago, and I've gotten a lot of very positive feedback that it's helpful.

(Also, this is taking me a really long time because right now I'm the only one putting any effort into this rewrite, and I'd really love to have some more folks helping me out! :) )

Thread Thread
 
emma profile image
Emma Goto 🍙

(Also, this is taking me a really long time because right now I'm the only one putting any effort into this rewrite, and I'd really love to have some more folks helping me out! :) )

I'd love to help out somewhere - I've only had real-world experience with old Redux (no hooks or RTK) so my knowledge may be a little bit outdated though. Is there somewhere specific I can start helping?

Thread Thread
 
markerikson profile image
Mark Erikson

Yeah, I'd appreciate it!

That "Overview" issue lists all the stuff I want to do for the docs, overall, and links to a prior issue where I laid out why I was wanting to make these changes.

Basically anything in that list is stuff I'd like help with. For example, the "Usage with Immutable.js" recipes page needs to go away, because we now specifically advise against using Immutable.js. There's a lot of pages that need to be shuffled around, FAQ entries ought to be updated to try to match the recommendations in the Style Guide, new "real world usage" sections need to be written, etc, etc.

Feel free to comment in github.com/reduxjs/redux/issues/3592 and we can figure out what would be a good place to start.