Component - Redux Toolkit setup
This UI component shows how to set up Redux Toolkit in a React Native app. It creates a store, provides it to the app, and connects a simple counter component to the store.
This UI component shows how to set up Redux Toolkit in a React Native app. It creates a store, provides it to the app, and connects a simple counter component to the store.
Provider
└── App
└── View
├── Text (Counter Display)
└── Button (Increment)configureStore in Redux Toolkit?configureStore roleconfigureStore is a Redux Toolkit function that simplifies creating the Redux store by automatically combining reducers and adding middleware.configureStore.configureStore creates store [OK]configureStore with an object argument containing the reducer key.reducer: rootReducer. Options A and C use old or invalid syntax. const store = configureStore(rootReducer); passes reducer directly without an object, which is incorrect.import { configureStore, createSlice } from '@reduxjs/toolkit';
const counterSlice = createSlice({
name: 'counter',
initialState: { value: 10 },
reducers: {
increment: state => { state.value += 1; }
}
});
const store = configureStore({ reducer: { counter: counterSlice.reducer } });
console.log(store.getState());initialState: { value: 10 } for the counter.counter, so the state shape is { counter: { value: 10 } }.import { configureStore } from '@reduxjs/toolkit';
const store = configureStore(reducer: rootReducer);
export default store;configureStore expects an object argument, so the reducer must be inside curly braces: { reducer: rootReducer }.<Provider store={store}><App /></Provider>
B) <StoreProvider store={store}><App /></StoreProvider>
C) <ReduxProvider store={store}><App /></ReduxProvider>
D) <App store={store} />Provider component from react-redux to supply the store to the app.Provider wraps the root App component with the store prop. Other options use incorrect or nonexistent components.Provider from react-redux to connect store [OK]Pass the test and this pattern moves unknown