0
0
React Nativemobile~20 mins

Redux Toolkit setup in React Native - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Redux Toolkit Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate
2: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
  }
});
Aconst store = configureStore({ reducer: { counter: counterReducer } });
Bconst store = configureStore(counterReducer);
Cconst store = configureStore({ reducer: counterReducer });
Dconst store = configureStore({ reducers: { 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.
ui_behavior
intermediate
1: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; }
  }
});
A0
Bundefined
Cnull
D10
Attempts:
2 left
💡 Hint
Look at the initialState property inside the slice.
lifecycle
advanced
2: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?
AOnly when the store is created
BOnly once during app initialization
CEvery time an action matching the slice's reducers is dispatched
DWhen the React component mounts
Attempts:
2 left
💡 Hint
Reducers respond to dispatched actions to update state.
navigation
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';
A<Provider store={store}><App /></Provider>
B<App><Provider store={store} /></App>
C<App store={store} />
D<Provider><App store={store} /></Provider>
Attempts:
2 left
💡 Hint
The Provider must wrap the entire app component tree.
🔧 Debug
expert
3: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);
AThe increment reducer mutates state directly, which is not allowed
BThe store reducer is not an object with slice name keys, so state shape is incorrect
CThe action is not dispatched correctly because increment is not exported
DThe initialState is missing, so state is undefined
Attempts:
2 left
💡 Hint
Check how the store reducer is configured and how the state is accessed in useSelector.