Answer the question
In order to leave comments, you need to log in
Why is the property name wrapped in square brackets in setState?
handleChange = type => ev =>{
const {value} = ev.target
if (value.length > limits.user.max) return
this.setState({
[type]: value
})
}
Answer the question
In order to leave comments, you need to log in
Computed property names .
This method stands on the onChange event.
handleChange = ({ target: { value, dataset: { type } } }) => {
if (value.length <= limits.user.max) {
this.setState({
[type]: value
});
}
}
<input onChange={this.handleChange} data-type="xxx">
<input onChange={this.handleChange} data-type="yyy">
<input onChange={this.handleChange} data-type="zzz">
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question