A
A
Arthur2018-03-18 11:33:30
React
Arthur, 2018-03-18 11:33:30

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>;
        }

I like this option better, but still wanted to know the opinion of experienced developers.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question