Is it possible to set the state with the switch instruction in the manner given below? Or maybe none of these ways is a good solution
Can I set:
return this.setState({
stat1: 'a'
})
or
return this.state.stat1 = 'a'
First way
books = (price) => {
switch(price) {
case 100:
return this.setState({
stat1: 'a'
})
case 1000:
return this.setState({
stat1: 'b'
})
case 2000:
return this.setState({
stat1: 'c'
})
default:
return this.setState({
stat1: ''
})
}
}
Second way
books = (price) => {
switch(price) {
case 100:
return this.state.stat1 = 'a'
case 1000:
return this.state.stat1 = 'b'
case 2000:
return this.state.stat1 = 'c'
default:
return this.state.stat1 = ''
}
}