Answer the question
In order to leave comments, you need to log in
How to increase the number?
Tell me how to make it so that when you click on the count button, one is added to the number?
import React from 'react';
import './App.css';
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
text: '',
count: 0,
}
}
showText = () => {
console.log('button work');
this.setState({ text: 'button work' });
}
showCount = () => {
this.setState({ count: '11' });
}
render() {
return (
<div>
<button onClick={this.showText}>Push1</button>
<p>{this.state.text}</p>
<button onClick={this.showCount}>Count</button>
<p>{this.state.count}</p>
</div>
)
}
}
export default App;
Answer the question
In order to leave comments, you need to log in
import React from 'react';
import './App.css';
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
text: '',
count: 0,
}
}
showText = () => {
console.log('button work');
this.setState({ text: 'button work' });
}
showCount = () => {
this.setState({ count: this.state.count + 1});
}
render() {
return (
<div>
<button onClick={this.showText}>Push1</button>
<p>{this.state.text}</p>
<button onClick={this.showCount}>Count</button>
<p>{this.state.count}</p>
</div>
)
}
}
export default App;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question