Upon clicking submit, I am looking to retrieve either a '+' or '-' result. However, I'm unsure of how to handle this within my code. Below is the code snippet along with the current result before 'submit' is clicked.
class App extends React.Component {
constructor() {
super();
this.state = {counter: 0};
}
render() {
return (
<div>
<button onClick={this.increment}>+</button>
<output>{this.state.counter}</output>
<button onClick={this.decrement}>-</button>
<button onClick={this.submit}>submit</button>
</div>
);
}
increment =()=> {
this.setState({
//counter: this.state.counter + 1
})
}
decrement=()=> {
this.setState({
//selectedFunction= -1???
})
}
submit=(selectedFunction)=>{this.setState({
counter: this.state.counter + {selectedFunction}
})};
}
ReactDOM.render(<App />, document.getElementById("app"));
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>