Complete the code to import the function needed to create a Redux store.
import { [1] } from '@reduxjs/toolkit';
The configureStore function from Redux Toolkit is used to create the Redux store easily with good defaults.
Complete the code to create a slice with a name and initial state.
const counterSlice = createSlice({
name: 'counter',
initialState: [1],
reducers: {}
});The initial state is usually an object with properties. Here, { value: 0 } sets the starting count.
Fix the error in the reducer function to correctly update the state.
reducers: {
increment: (state) => {
state.value [1] 1;
}
}= which replaces the value.== which does not change the value.++ which is not valid syntax here.To increase the value by 1, use the += operator. It adds 1 to the current state value.
Fill both blanks to export the reducer and actions from the slice.
export const { [1] } = counterSlice.actions;
export default counterSlice.[2];We export the increment action from counterSlice.actions and the default export is the reducer from the slice.
Fill all three blanks to configure the Redux store with the counter reducer.
const store = configureStore({
reducer: {
[1]: [2]
},
middleware: (getDefaultMiddleware) => getDefaultMiddleware().[3]()
});The store reducer key is counter, the reducer function is counterReducer, and prepend() adds middleware at the start.