score:3

Accepted answer

the documentation of react date time picker you have used uses onchange function programmatically and does not relay the change event back to the user. instead the parameter inside onchange is the moment date object itself.

class app extends react.component {
  constructor(props) {
    super(props);
    this.state = {
      datetime: ''
    }
    this.updatestate = this.updatestate.bind(this);
  }
  updatestate(date) {
    // this function gives you the moment object of date selected. 
    console.log(date);
  }
  render() {
    return (
      <datetime onchange={this.updatestate}/>
    );
  }
}
reactdom.render(<app />, document.getelementbyid("root"));
<link rel="stylesheet" type="text/css" href="https://rawgit.com/arqex/react-datetime/master/css/react-datetime.css"/>

<div id="root"></div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.19.3/moment.js"></script>
<script src="https://rawgit.com/arqex/react-datetime/master/dist/react-datetime.js"></script>

something else you should look up is how to use setstate callback. because setstate is asynchronous, you cannot use a function to log the state value.


Related Query

More Query from same tag