I declared a state in baseReducer.ts:
import {PayloadAction} from '~common/declarations/action';
const initialState = {
test: 'baseReducer'
};
const BaseReducer = (state = initialState, action: PayloadAction<any>): any => {
switch(action.type) {
default:
return state;
}
}
export default BaseReducer;
Then in my orderReducer:
import {PayloadAction} from '~common/declarations/action';
const initialState = {
test: 'orderReducer'
};
const OrderReducer = (state = initialState, action: PayloadAction<any>): any => {
switch(action.type) {
default:
return state;
}
}
export default OrderReducer ;
In my rootReducer:
const RootReducer: Reducer = combineReducers({
BaseReducer,
OrderReducer
});
export default RootReducer;
Now in my functional component OrderPage.tsx:
export default function OrderPage() {
const stringText: string = useSelector(state => state.test) // HERE
return (
<React.Fragment>Order Page</React.Fragment>
);
}
Here is my question:
How do I define which state to take from? Ideally I want to specify the state from OrderReducer.
When using react Classes, I could do the following:
const mapStateToProps = ({orderReducer}) => {
return {
test: orderReducer.test
}
}
Edit:
I tried the following (separately of course!), but it did not work:
const reducer: string = useSelector(state => state.baseReducer);
const reducer: string = useSelector(state => state.orderReducer);
How do I achieve the same in function components?