Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running into problems using React Datepicker with rails

I am using this datepicker plugin for react: https://github.com/Hacker0x01/react-datepicker

I keep getting the following error: Uncaught TypeError: this.props.moment is not a function in react-datepicker.min.js.

I just copied the example code, and I can see the input field, but whenever I click on it to render the calendar, it keeps giving the error above. Anyone know had this issue in the past?

like image 829
user3769323 Avatar asked Sep 19 '26 23:09

user3769323


1 Answers

Just resolved it, it was a matter of not requiring the "moment" js file in application.js. If you use bundler to install this plug in be sure to add the following into the gemfile:

source "https://rails-assets.org" do
  gem 'rails-assets-react-date-picker'
  gem "rails-assets-moment"
end

and then require both in application.js in this order:

//= require "moment"
//= require "react-date-picker"
like image 166
user3769323 Avatar answered Sep 21 '26 13:09

user3769323



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!