Answer the question
In order to leave comments, you need to log in
Are you using experimental syntax in React JS?
Good afternoon, I started to learn React JS and a question arose.
Is it possible to use this syntax to manage state?
state = {
class: 'off',
label: 'Нажми'
}
press = () => {
let className = (this.state.class==="off")?"on":"off";
let label = (this.state.label === 'Нажми')?'нажми еще раз?':'Нажми';
this.setState({class: className, label: label});
}
render() {
return <button onClick={this.press} className={this.state.class}>{this.state.label}</button>;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question