This course has been updated! We now recommend you take the Intermediate React, v3 course.
Transcript from the "Creating a Store" Lesson
>> 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,
>> 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.
>> 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.