Answer the question
In order to leave comments, you need to log in
Why does the code run one step late? Where is the mistake?
I am writing a calculator in react
constructor() {
super();
this.state = {
valueInput: 0,
firstOperand: '',
secondOperand: '',
result: '',
}
this.renderButton = this.renderButton.bind(this);
this.refreshInput = this.refreshInput.bind(this);
}
refreshInput(event) {
const target = event.target.innerHTML;
//if you clicked a number
if(!isNaN(parseFloat(target)) && isFinite(target)) {
this.setState({
firstOperand: this.state.firstOperand + target,
valueInput: this.state.firstOperand,
})
}
}
Answer the question
In order to leave comments, you need to log in
refreshInput(event) {
const target = event.target.innerHTML;
//if you clicked a number
if(!isNaN(parseFloat(target)) && isFinite(target)) {
let number = this.state.firstOperand + target
this.setState({
firstOperand: number,
valueInput: number,
})
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question