farmcommand2
farmcommand2

Reputation: 1496

map multi states to a component

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

Answers (1)

madox2
madox2

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

Related Questions