chrisdavies / tiny-date-picker

A small, modern, dependency-free date picker
https://chrisdavies.github.io/tiny-date-picker/
415 stars 87 forks source link

Does this datepicker support React? #107

Open javeedrahman opened 5 years ago

kevinfiol commented 3 years ago

Hey @javeedrahman . I'm a little late, but you can easily integrate this lib (and other vanilla JS libs) in React by using a ref. Take a look https://reactjs.org/docs/integrating-with-other-libraries.html

johannes-ross commented 3 years ago

Hey, just ran over the same "Problem". I made a wrapper class:

import React from "react";
import TinyDatePicker from 'tiny-date-picker';
// Make sure, we have all the CSS
import 'tiny-date-picker/tiny-date-picker.min.css';

export default class TinyDatePickerReact extends React.Component {
        // I use TypeScript so el is any
    el:any = null;
    componentDidMount() {
                // create the Datepicker
        this.el = TinyDatePicker(this.el);
                // Do something with it
        this.el.open();
    }

    componentWillUnmount() {
                // If this compontents gets removed, remove the Datepicker first
        this.el.destroy();
    }

    render() {
                // reference an input element
        return <input ref={el => this.el = el} />;
    }
}

Hope I could help.