Last active
October 18, 2017 19:16
-
-
Save kanhirun/5c0ce732d9cb17d07023baf3c815e39b to your computer and use it in GitHub Desktop.
mapStateToProps - strict filtering done by destructuring
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // es6 | |
| const aStateThatCanBeSliced = { | |
| fruits: { | |
| oranges: 999999, | |
| bananas: 10 | |
| }, | |
| hasFreshFruits: true, | |
| } | |
| const aStateThatCannotBeSliced = { | |
| goats: 999 | |
| } | |
| // Proposal | |
| const mapStateToProps = state => { | |
| const { fruits: { bananas } } = state; | |
| return { fruits: { bananas } }; | |
| } | |
| console.log(mapStateToProps(aStateThatCanBeSliced)) // => { fruits: { bananas: 10 } } | |
| console.log(mapStateToProps(aStateThatCannotBeSliced)) // TypeError |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment