I want to let the user input the clicks times and increase it with a button, but I don't know-how.
Here's the code.
import React, { Component } from "react";
class Click extends Component {
constructor(props) {
super(props);
this.state = {
clicks: 0,
show: true,
};
}
IncrementItem = () => {
this.setState({ clicks: this.state.clicks + 1 });
};
DecreaseItem = () => {
if (this.state.clicks < 1) {
this.setState({
clicks: 0,
});
} else {
this.setState({
clicks: this.state.clicks - 1,
});
}
};
ToggleClick = () => {
this.setState({ show: !this.state.show });
};
handleChange(event) {
this.setState({ clicks: event.target.value });
}
render() {
return (
<div>
<button onClick={this.DecreaseItem}>Click to decrease by 1</button>
<button onClick={this.IncrementItem}>Click to increase by 1</button>
<button onClick={this.ToggleClick}>
{this.state.show ? "Hide number" : "Show number"}
</button>
{this.state.show ? ( <input type="number" name="clicks" value={this.state.clicks}onChange = {this.handleChange.bind(this)}/>) : (" ")}
</div>
);
}
}
export default Click;