Get started with react-datepicker CDN

MIT licensed

React-datepicker is a popular React library for building custom date pickers.

Tags:
  • react
  • datepicker
  • calendar
  • date
  • react-component

Stable version

Copied!

How to start using react-datepicker CDN


import React from 'react';
import DatePicker from 'react-datepicker'; // Import the DatePicker component
import 'react-datepicker/dist/react-datepicker.css'; // Import the CSS for DatePicker

class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      startDate: new Date(),
    };

    this.handleChange = this.handleChange.bind(this);
  }

  handleChange(date) {
    this.setState({ startDate: date });
  }

  render() {
    return (
      <div>
        <h1>Select a date:</h1>
        <DatePicker
          value={this.state.startDate}
          onChange={this.handleChange}
        />
        <p>You picked: {this.state.startDate.toLocaleDateString()}</p>
      </div>
    );
  }
}

export default App;
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!

All versions