Answer the question
In order to leave comments, you need to log in
How to combine several reducers into one using combineReducers?
I'm trying to combine several reducers into one using combineReducers but it doesn't work.
Here is the code:
store.js
import { combineReducers, createStore } from "redux";
const initialStateOne = {
myState: 1,
};
const initialStateTwo = {
myState: 2,
};
const reducerOne = (state = initialStateOne, action) => {
return state;
};
const reducerTwo = (state = initialStateTwo, action) => {
return state;
};
const rootReducer = combineReducers({
one: reducerOne,
two: reducerTwo,
});
export default store = createStore(rootReducer);
import React from "react";
import { NavigationContainer } from "@react-navigation/native";
import { createStackNavigator } from "@react-navigation/stack";
import { Provider } from "react-redux";
import store from "./src/store";
import NewComponent from "./src/NewComponent";
const Stack = createStackNavigator();
export default function Navigation() {
return (
<Provider store={store}>
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen
name="NewComponent"
component={NewComponent}
/>
</Stack.Navigator>
</NavigationContainer>
</Provider>
);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question