简体   繁体   中英

Why is mapStateToProps needed if I can use the entire store in my component?

From definition

mapStateToProps is used for selecting the part of the data from the store that the connected component needs.

I didn't understand why do we even have to specify mapStateToProps if I can use the entire store data in my component, what exactly does mapStateToProps provides? What will happen if I select some part of data?

Any advantages?

  • mapStateToProps gives you only the p arts of the store you need in the component.
  • It calls every time the store state changes (every time the relative part of the store that you return is changed).
  • It can return different structures of the store data
  • Can return different structures of the store data for different component props.
  • Can be re-used for different components that need the same parts of the store

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM