handleChange(event) {
const {name, value} = event.target
this.setState({
[name]: value
})
}
this is a method that notes for change in state of a react component. takes event as parameter and does something and changes state.
handleChange(event) {
const {name, value} = event.target
this.setState({
[name]: value
})
}
this is a method that notes for change in state of a react component. takes event as parameter and does something and changes state.
This method is called destructuring, which is used to save some few lines.
The following example will show you the usage of destructuring.
let person = {
name: 'David',
age: 15,
job: 'Programmer'
}
const { name, age } = person; // Takes the property/method from the object
console.log(name); // Prints 'David'
console.log(age); // Prints '15'
Without using destructuring, I would have done this:
const name = person.name;
const age = person.age;
Which needed more lines.
You can read more about destructuring here.
event.target means element where you pass the function, and { name } this technique is called destructing it is same as const name = event.target.name
for example if you pass handleChange to some input event.target is input where you passed handleChange function