Skip to content

Conversation

@aminsoheyli
Copy link
Contributor

add a line to insist on the pure nature of mapStateToProps function

add a line to insist on the pure nature of mapStateToProps function
@netlify
Copy link

netlify bot commented Aug 26, 2019

Deploy preview for react-redux-docs ready!

Built with commit 4bd70e0

https://deploy-preview-1386--react-redux-docs.netlify.com

@timdorr
Copy link
Member

timdorr commented Aug 27, 2019

I integrated it into an existing sentence so it doesn't add so much to the original content. Thanks for the starting point!

@timdorr timdorr merged commit e228b32 into reduxjs:master Aug 27, 2019
Copy link
Contributor Author

@aminsoheyli aminsoheyli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a great reordering.
Thanks!

### `mapStateToProps` Functions Should Be Pure and Synchronous
Much like a Redux reducer, a `mapStateToProps` function should always be 100% pure and synchronous. It should simply take `state` (and `ownProps`) as arguments, and return the data the component needs as props. It should _not_ be used to trigger asynchronous behavior like AJAX calls for data fetching, and the functions should not be declared as `async`. Also it should not mutate the `state` or the `ownProps`.
Much like a Redux reducer, a `mapStateToProps` function should always be 100% pure and synchronous. It should only take `state` (and `ownProps`) as arguments, and return the data the component needs as props without mutating those arguments. It should _not_ be used to trigger asynchronous behavior like AJAX calls for data fetching, and the functions should not be declared as `async`.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!👌

albertodev7 pushed a commit to albertodev7/react-redux that referenced this pull request Dec 8, 2022
* add a line to insist on the pure nature

add a line to insist on the pure nature of mapStateToProps function

* Reorder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants