Learn Redux - Wes Bos Flashcards
Within React Router, what is an IndexRoute?
When routes are nested, declaring a route as an IndexRoute instead of just a Route means that if the base url is visited, the IndexRoute is the route which will be fed to the main parent by default, the other will have to be explicitly visited.
What is the main difference with Redux over plain React?
We keep all of our data within a single Store rather than holding our state in a bunch of component states. We have one giant object that contains all of our data for all of our store.
How do we see what is in our store (from within the console, say)
Provider.store.getState()
What are the two core components behind working with Redux?
Reducers and Actions
Where do we create our store.js file?
Within our client folder (not within the components folder)
What is the benefit of using syncHistoryWithStore?
We can hook up ReactRouter with our Redux instance.
Why do we import browserHistory from React Router into our Redux Store instead of directly into our main app file?
Because we will need to modify its behavior slightly to sync it up with Redux.
What two arguments does the Redux createStore command take?
the first if the rootReducer (imported from the reducers index) the second is the defaultState - which can just be an object literal declared within the statement, but it’s clearer to usually set it up as a separte variable and then just pass that variable as the argument.
What is going on in this statement below? export const history = syncHistoryWithStore(browserHistory, store);
We are taking the browser history and the push state, and then weaving in the actual store - we will need this history then to be accessible to other files because although we are creating it here, we will actually be using it elsewhere. We export it because that’s how you get something out of one file and into another.
What are Redux Actions?
Think of an Action as something that happens in your application - someone clicks on a photo, adds a comment, likes a picture or whatever. Whenever something happens, Redux dispatches an action.
What two things does a Redux dispatchAction contain?
- ) The type of action that happened (maybe ‘incrementLikes’ or ‘addComment’ or whatever)
- ) A payload of info that is needed - WHICH comment was deleted - who was the author - this is the info about the specifics of what happened.
Where do we create our Redux actions?
Within an ‘actions’ folder, under the client folder. Within this folder, we can either have one giant ‘actionCreators.js’ file - or we can break them off into individual files if we have a lot of them going on.
What does a Redux ActionCreator do?
It puts the action object together and dispatches it to our Reducer.
Within React, what actually updates our state?
Our Reducers handle and update the actual state.
What is a helpful way to think of actions?
As regular JS actions that just get fired off - but if no function is listening to that click or button or whatever - then nothing actually happens.