How integrate jQuery plugin in React

后端 未结 2 1199
孤街浪徒
孤街浪徒 2021-02-06 11:30

I want to use https://github.com/t1m0n/air-datepicker with in a React app, but it doesn\'t work.

2条回答
  •  一向
    一向 (楼主)
    2021-02-06 11:53

    First of all air-datepicker is not React component, it's jQuery plugin, so it won't work like in your examples.

    Secondly, for proper work, jQuery should be availabel in global context, the most esiest ways to do this is to include it into page via

As separate component

Very simple datepicker React component example

class Datepicker extends React.Component {
  componentDidMount(){
    this.initDatepicker();
  }
  
  initDatepicker(){
    $(this.refs.datepicker).datepicker(this.props);
  }

  render(){
    return (
      
    )
  }
}


class MyComponent extends React.Component {
  render(){
    return (
      

Choose date from React Datepicker!

) } } ReactDOM.render( , document.getElementById('app') );







Also don't forget to include css files.

提交回复
热议问题