Redux Toolkit Flashcards

1
Q

What does configure store take as a parameter?

A

an object

configureStore accepts a single configuration object parameter.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does the createSlice method take as a parameter?

A

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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What determines the first part of an actions name? for example todos/addTodo where does the todo part come from ?

A

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'
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a good way to think about the naming of the type property of an action?

A

name of the slice/name of the reducer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a thunk?

A

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');
  };
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the key phrase to understand thunks?

A

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');
  };
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What two arguments does createAsyncThunk require?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly