d-ivashchuk / memory-helper

A very tiny React application that lets you record memories and associate them with the weather (city of your chosing or shared location through browser).)
https://silly-borg-178afb.netlify.com/
MIT License
0 stars 0 forks source link

Destructure state and props #4

Open d-ivashchuk opened 5 years ago

d-ivashchuk commented 5 years ago

https://github.com/d-ivashchuk/memory-helper/blob/0ea43d5c6eb9e4175ceabf94ad60727c184a231f/src/Entry/entry.jsx#L44

d-ivashchuk commented 5 years ago

Notice with what frequency you use this pattern: this.state.smth, this.props.smth in your components? It could be overwhelming, as we generally understand from where this variable comes from. That's where destructuring comes to the rescue. You could have smth like :

const {smth1,smth2,smth3} = this.state
const {prop1,prop2,prop2} = this.props

and then instead of having it this way:

this.props.prop1, this.state.smth2 you would be able to use them like smth1, prop2, smth3 etc.