Basic Tutorial Flashcards
What are actions?
Actions are plain JavaScript objects or payloads of information that send data from your application to your store.
What is the only source of information for the store?
Actions.
How do you send an action to the store?
By using using store.dispatch().
What must actions have?
A type property that indicates the type of action being performed.
What should types typically be defined as?
String constants.
What is this an example of?
const ADD_TODO = ‘ADD_TODO’
{
type: ADD_TODO,
text: ‘Build my first Redux app’
}
An action which represents adding a new todo item.
What might you want to do once your app is large enough?
Move Actions into a separate module.
It’s a good idea to pass as little data in each action as possible.
For example, it’s better to pass index than the whole todo object.
What are action creators?
Functions that create actions.
Why would you use an action creator to return an action?
To make them portable and easy to test.
What is an example of an action creator?
function addTodo(text) { return { type: ADD_TODO, text } }
How would you initiate a dispatch in Redux?
Pass the result to the dispatch() function, or create a bound action creator that automatically dispatches.
Give a simple example of passing a result to a dispatch() function.
dispatch(addTodo(text))
dispatch(completeTodo(index))
Give a simple example of how you would create a bound action creator that automatically dispatches.
const boundAddTodo = text => dispatch(addTodo(text)) const boundCompleteTodo = index => dispatch(completeTodo(index))
What is the advantage of using a bound action creator that automatically dispatches?
You can call them directly.
Give a simple example of how you would directly call a bound action creator that automatically dispatches.
boundAddTodo(text)
boundCompleteTodo(index)
How would you directly access the the dispatch() function from the store?
by using store.dispatch() or more likely by accessing it using a helper like react-redux’s connect().
How would you automatically bind many action creators to a dispatch() function?
By using bindActionCreators()
What do reducers do?
They specify how the application’s state changes in response to actions sent to the store.
How do actions differ from reducers?
Actions only describe what happened, but don’t describe how the application’s state changes.
How is all the applications state stored?
In a single object.
What is a good practice before creating an apps state?
To figure out the minimal representation of your app’s state as an object.
what should you do if you need to store some data, as well as some UI state, in the state tree?
Try to keep them separate.
What’s a best practice when creating an apps state?
To keep it as normalized as possible, without any nesting and to keep every entity in an object stored with an ID as a key, and use IDs to reference it from other entities, or lists.