Redux Flashcards
Architecture where shared information is found in a single object
Flux Architecture
What are the 2 key/ value pairs in an Action Object?
type and payload
const action = {
type: ‘todos/ addTodo’,
payload: ‘Take Selfies’
}
The single source of truth in flux architecture
Store
What 2 parameters are required in a reducer function?
store and action
const reducer = (store = initialState, action) => {
switch(action.type) {
case ‘addTodo’: {
return […store, action.payload]
}
}
}
Inside of the reducer function, the switch statement should always default to what?
Returning the store
default: {
return store
}
Rules of Reducers
- Only calculate a new state value based on _____ and _____ arguments
- Cannot directly _____ state. Only make changes to _____ values
- No _____ logic or other _____
- Only calculate a new state value based on state (store) and action arguments
- Cannot directly modify state. Only make changes to copied values
- No asynchronous logic or other side effects
What 2 aspects define a pure function?
- Same input, same output
- No side effects (immutable)
The store contains what 2 items?
Reducer and state
➡️ Store ➡️ _____ ➡️ _____ 🔁
UI and dispatch
The dispatch is an event handler containing what?
An action object