reactjspikaday

How can I use Pikaday with ReactJS?


I would like to use the Pikaday datepicker with ReactJS. It is not based on ReactJS. How can I use it?


Solution

  • To use Pikaday with ReactJS you can require it as you would any other node module. The trick is to hook into the React rendering event so that after the view is rendered, Pikaday is initialized on any rendered DOM inputs you want to use it on. You can do this with the ReactJS lifesystle event componentDidRender:

      componentDidMount: function() {
        new Pikaday({
          field: React.findDOMNode(this.refs.start),
          format: 'MM/DD/YYYY',
          onSelect: this.onChangeStart
        });
    
        new Pikaday({
          field: React.findDOMNode(this.refs.end),
          format: 'MM/DD/YYYY',
          onSelect: this.onChangeEnd
        });
      }