I don´t understand how this code works. How does it set the state using the regex? And most importantly, how does it know to set the state using the result variable?
handleClick(evt) {
const id = evt.target.id;
const result = evt.target.value;
this.setState(prevState => ({
value: `${prevState.value}${result}`
.replace(/([/+\-/*=])([/+\-*=])/g, "$2")
.replace(/^0+(?=[1-9])/, "")
.replace(/^0+(?=\.)/, "0")
.replace(/^0+\B/, "")
}));
}
}