Redux Toolkit Flashcards
What does configure store take as a parameter?
an object
configureStore accepts a single configuration object parameter.
What does the createSlice method take as a parameter?
It accepts an object with the following properties,
- name – which is a string,
- initial state – which can be any data type
- reducers – An object containing Redux “case reducer” functions
What determines the first part of an actions name? for example todos/addTodo where does the todo part come from ?
It comes from the name property of the object passed to the createSlice function.
export const todoSlice = createSlice({ name: "todos2", initialState: { allTodos: [] }, reducers: { ...etc
This makes sense as the action creators are created by createSlice. The type property of an action needs to know this information.
const addTodoAction = { type: 'todos2/addTodo', payload: 'Buy milk' }
What is a good way to think about the naming of the type property of an action?
name of the slice/name of the reducer
What is a thunk?
A thunk is another word for a function. But it’s not just any old function. It’s a special (and uncommon) name for a function that’s returned by another. Like this:
function wrapper_function() { // this one is a "thunk" because it defers work for later: return function thunk() { // it can be named, or anonymous console.log('do stuff now'); }; }
What is the key phrase to understand thunks?
A thunk defers work for later.
My understanding at this point is that a thunk is a function returned by another function. Something happens once the returned function is invoked.
function wrapper_function() { // this one is a "thunk" because it defers work for later: return function thunk() { // nothing happens until this is called console.log('do stuff now'); }; }
What two arguments does createAsyncThunk require?
The first argument is a Redux action type string e.g. ‘todos/todoAdded’
The second argument is a callback function that should return a promise.