This course has been updated! We now recommend you take the Intermediate React, v5 course.

Check out a free preview of the full Intermediate React, v2 course:
The "Creating a Store" Lesson is part of the full, Intermediate React, v2 course featured in this preview video. Here's what you'd learn in this lesson:

Brian begins creating a Redux store, which is at its core a reducer.

Get Unlimited Access Now

Transcript from the "Creating a Store" Lesson

[00:00:00]
>> Brian Holt: New file, save it, call it inside of src, and call it store.js. Inside of store, I want you to import createStore, compose, and apply middleware.
>> Brian Holt: Actually we don't need apply middleware, you can leave that one out, so just compose.
>> Brian Holt: I don't think you even need compose.

[00:00:33] So just createStore from redux. Then import, we're gonna import a reducer from ./reducers, but we haven't made that yet, so that will just be an error for right now. const store = createStore(reducer) and export default store.
>> Brian Holt: So at its most basic, this is what redux is. You have one root reducer which if you remember from the hooks section of this, they're gonna look exactly the same, right?

[00:01:12] So this is the root reducer. So it's a function that takes in an old state, and gives you back new state. So that's what this is, it's just a function. And then this is the central repository of store, which we're going to eventually connect to React here in just a second.

[00:01:31] Now, we're gonna do one more thing here. We're gonna give it this kind of black magic voodoo that allows us to use the redux dev tools as well. So we're gonna say if typeof window, so if we're in the browser, so if this is equal to object and,

[00:01:53]
>> Brian Holt: And typeof window.__REDUX_DEVTOOLS_EXTENSION__ is not equal to undefined. So basically it's saying if I'm in the browser and the redux dev tools exist, let's go ahead and use that. So if that's true, then you're gonna say. I'll just copy and paste that. Call that function, otherwise, just give it some random function to use, so F to F.

[00:02:40]
>> Brian Holt: So what this blob of code does, again, if the Redux DevTools exists, use them. If it doesn't, give it some bogus function which is exactly what this is.
>> Brian Holt: Makes sense? Yeah, cool, from here, I know. The one other thing is, if you wanted to use something like thunks, or sagas, or redux observable, or something like that, you would do that here, as well.

[00:03:10] We're not going, but this is where you would do it.