How does react use input to get the value of a decimal number?

JS Bin on jsbin.com

when the decimal point is deleted, it is impossible to enter the decimal point again. How to solve this problem?

can you do the following functions similar to vue

feels that react is really too troublesome to do this.

May.26,2021

+ event.target.value will drop the decimal point Filter, so you must remove the +

.
handleChange(event) {
    this.setState({value: event.target.value});
}

Please post the code directly. It's best not to give an outer chain like this.

Please use + expression

correctly
class HelloMessage extends React.Component {
  constructor(props) {
      super(props);
      this.state = {value: 1.1};
      this.handleChange = this.handleChange.bind(this);
  }
 
  handleChange(event) {
    this.setState({value: event.target.value});
  }
  render() {
    var value = this.state.value;
    return <div>
          <input type="text" value={this.state.value} onChange={this.handleChange} />
        <div>{this.state.value}</div>
        <div>{Number.isNaN(Number(this.state.value)) ? '' : ''}</div>
        
 
        </div>;
  }
}
ReactDOM.render(
  <HelloMessage />,
  document.getElementById('example')
);
Menu