Challenge - 5 Problems
Redux Toolkit Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate2:00remaining
Identify the correct Redux Toolkit store setup
Which option correctly creates a Redux store using Redux Toolkit's
configureStore with a single reducer named counter?React Native
import { configureStore } from '@reduxjs/toolkit'; import counterReducer from './counterSlice'; const store = configureStore({ reducer: { counter: counterReducer } });
Attempts:
2 left
💡 Hint
Remember that
configureStore expects an object with a reducer property that is an object mapping slice names to reducers.✗ Incorrect
Option A correctly passes an object with a
reducer property containing the counter slice reducer. Option A passes the reducer directly, which is invalid. Option A passes the reducer directly without wrapping in an object. Option A uses reducers instead of reducer, which is incorrect.❓ ui_behavior
intermediate1:30remaining
Redux Toolkit slice initial state behavior
Given this slice setup, what is the initial value of
state.value when the app starts?React Native
import { createSlice } from '@reduxjs/toolkit'; const counterSlice = createSlice({ name: 'counter', initialState: { value: 10 }, reducers: { increment: state => { state.value += 1; } } });
Attempts:
2 left
💡 Hint
Look at the
initialState property inside the slice.✗ Incorrect
The
initialState is set to an object with value: 10, so the initial state.value is 10.❓ lifecycle
advanced2:00remaining
When does Redux Toolkit's
createSlice reducer get called?In a React Native app using Redux Toolkit, when is the reducer function inside
createSlice called?Attempts:
2 left
💡 Hint
Reducers respond to dispatched actions to update state.
✗ Incorrect
Reducers created by
createSlice run every time an action matching their name is dispatched to update the state accordingly.advanced
2:00remaining
Connecting Redux store to React Native app
Which option correctly wraps the React Native app with the Redux
Provider to make the store available?React Native
import { Provider } from 'react-redux'; import store from './store'; import App from './App';
Attempts:
2 left
💡 Hint
The
Provider must wrap the entire app component tree.✗ Incorrect
Option A correctly wraps
App inside Provider passing the store as a prop. Other options either pass the store incorrectly or do not wrap the app properly.🔧 Debug
expert3:00remaining
Why does dispatching an action not update state?
Given this slice and store setup, why does dispatching
increment() not update the UI?React Native
import { createSlice, configureStore } from '@reduxjs/toolkit'; const counterSlice = createSlice({ name: 'counter', initialState: { value: 0 }, reducers: { increment: state => { state.value += 1; } } }); const store = configureStore({ reducer: counterSlice.reducer }); // In component // dispatch(counterSlice.actions.increment()); // useSelector(state => state.counter.value);
Attempts:
2 left
💡 Hint
Check how the store reducer is configured and how the state is accessed in useSelector.
✗ Incorrect
The store reducer is set directly to the slice reducer function, so the state shape is just the value object. But the component tries to access state.counter.value, which is undefined. The reducer should be passed as an object with key 'counter' to match the state shape.