-
-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Description
We don't want anyone using the core createStore method directly in their apps today. We want them using configureStore from RTK instead.
We should tag createStore as @deprecated on both the 4.x and 5.x branches, and do another 4.x release.
edit
After a bunch of discussion, it's become clear that a lot of people aren't familiar with what RTK actually is, or what the technical differences are between the core createStore API and RTK's configureStore. Let me provide some background resources.
First, I had a chance to do a livestream with Jason Lengstorf where we explained what people disliked about Redux historically, and how RTK was created to solve those issues. We then built a small example app with RTK+TS:
Next, the "Modern Redux with RTK" tutorial page shows the differences in usage between "vanilla" Redux and RTK for things like store setup and writing reducers:
And for a lot of additional background on why RTK was created and how it evolved, see my "Redux Toolkit 1.0" announcement post.
For the actual technical differences, Lenz had a very good explanation on Twitter today:
In short:
configureStorecallsapplyMiddlewareandcombineReducersfor you and sets up the devtools, all while having a more "sane" api thancreateStore. For that reason alone, it should be a technical successor ofcreateStore.
In dev, it also adds two additional middlewares per default (middleware added byconfigureStoreis freely configurable): One checks for accidental store mutations, both between renders as well as inside the reducer.
That means it eliminates a whole class of bugs that only surface in "UI sometimes not rerendering" or things "being out of order some time later" - hard and frustrating to find. The other warns if you put non-(de)serializable values like classes into the store.
Not only do these make a lot of problems with the devtools or libraries like redux-persist, even something as simple as a Date instance can mutate itself out of the normal Redux data flow.
So, even if you were not to use the rest of RTK (which still makes you life a lot easier beyond that, removing the need for action types and manual immutable logic), it would still be a good idea to install RTK and use onlyconfigureStoreout of it, instead ofcreateStore.
There's some comparisons of the before and after setup here: