Reputation: 1496
I'm trying to map two parts of the state to my component. Is the way below ok to map multi states to a component? it works but I don't know if it makes you experts laugh at my code !! I mean is there another way that you rather?
const mapStateToProps = state => {
return ( state.auth, state.sina );
};
this one also worked:
const mapStateToProps = state => {
return {...state.auth, ...state.sina};
};
Upvotes: 1
Views: 48
Reputation: 51881
mapStateToProps
is regular javascript function. You can return object literal with any properties you wish, for example:
const mapStateToProps = state => {
return {
auth: state.auth,
sina: state.sina
};
};
And then access it inside of your component:
this.props.auth;
this.props.sina;
Upvotes: 3