I was learning ReactJS here: https://egghead.io/lessons/react-dynamically-generated-components and came across this code snippet:
componentWillMount(){
fetch( 'http://swapi.co/api/people/?format=json')
.then( response => response.json() )
.then( ({results: items}) => this.setState({items}) )
}
What does the ({results: items})
part of the arrow function mean?
I've seen arrow function
- with no parameter
()=>console.log('hi')
- without parenthesis
word=>console.log(word)
- and with multiple parameter seperated by comma
(one, two)=>console.log(one)
But never an object literal in this way.
Also, why does this.setState({items})
need curly braces around items
? What does it all mean?