gusparis / react-native-month-year-picker

React Native Month Picker component for iOS & Android
MIT License
106 stars 74 forks source link

TypeError: value.getTime is not a function. (In 'value.getTime()', 'value.getTime' is undefined) #43

Closed dineshchaudhary923092 closed 3 years ago

dineshchaudhary923092 commented 3 years ago

Giving TypeError in both android and ios after upgrading to 1.4.1.

Simulator Screen Shot - iPhone 11 - 2020-10-09 at 01 47 07 WhatsApp Image 2020-10-09 at 01 47 36

gusparis commented 3 years ago

Thank for using the library! It looks like you're sending an incorrect Date object. Can you share the code of your implementation?

dineshchaudhary923092 commented 3 years ago

Really appreciate the response time. Thank you

const [month, setMonth] = useState(moment(new Date()).format('MM YYYY'))

const onValueChange = (event, newDate) => { setShowPicker(false); const selectedMonth = newDate || month; setMonth(selectedMonth); }

<MonthPicker onChange={onValueChange} value={month} minimumDate={new Date(2019, 12)} maximumDate={new Date(2025)} enableAutoDarkMode={true} outputFormat='MM YYYY' okButton="Select" />

gusparis commented 3 years ago

Ohh, I see. You are sending a moment object with outputFormat. I have deprecated that prop to decouple the component. Just send a Date object, and handle the logic on your side, when calling onChange using the line you have in the useState. Let me know how it goes.

dineshchaudhary923092 commented 3 years ago

Working Perfectly, Thank you very much