BugiDev / react-native-calendar-strip

Easy to use and visually stunning calendar component for React Native.
MIT License
949 stars 327 forks source link

TypeError: Cannot read property 'clone' of undefined #257

Closed ganesh-papola closed 3 years ago

ganesh-papola commented 3 years ago

Android/ios release error in date clone

TypeError: Cannot read property 'clone' of undefined

This error is located at:
    in CalendarStrip (at DatePicker.js:64)
    in RCTView (at View.js:34)
    in View (at DatePicker.js:55)
    in App (at EventList.js:259)
    in RCTView (at View.js:34)
    ...
peacechen commented 3 years ago

This project doesn't have a file named DatePicker.js. Is that in your code? As with the other issue that you posted, please include a reproducible demo or code snippet. Use the example project in this repo as a base if that's convenient.

ganesh-papola commented 3 years ago
<CalendarStrip
            scrollable
            minDate={new Date()
            style={{ height: hp(100), paddingTop: hp(20), paddingBottom: hp(20) }}
            calendarHeaderStyle={{ color: 'white', paddingBottom: hp(7) }}
            calendarColor={COLORS.PRIMARY}
            dateNumberStyle={{ color: 'white', }}
            dateNameStyle={{ color: 'white', }}
            iconContainer={{ flex: 0.1 }}
            selectedDate={this.state.selectedDate}
            onDateSelected={this.onDateSelected}
            onWeekChanged={this.props.onWeekChanged?this.props.onWeekChanged:null}
            useIsoWeekday={false}
            iconLeft={require('../images/left-arrow.png')}
            iconRight={require('../images/right-arrow.png')}
            highlightDateNameStyle={'black'}
            highlightDateNumberStyle={'black'}
            calendarAnimation={{ type: 'sequence', duration: 30 }}
           daySelectionAnimation={{ type: 'border', duration: 200, borderWidth: 1, borderHighlightColor: 'white', highlightColor: 'black' }}
          />
      this is the code in DatePicker.js
Screenshot 2021-01-10 at 7 14 39 PM
peacechen commented 3 years ago

I can help debug if you provide a Snack that recreates the bug. Otherwise StackOverflow is a better forum for general React Native questions

hans-permana commented 3 years ago

I encountered the same issue. I use the version 2.1.4

This is fixed when the startingDate is given a value. Maybe this should be made mandatory in the TS? Also, I found it tricky dealing with momentjs object since this object is mutable. I understand now why there are a lot of clones in the code. Anyway, awesome library!

peacechen commented 3 years ago

Thanks @hans-permana for the additional info. The startingDate prop is checked for null and set to today's date. Which line is the clone exception happening?

I agree that Moment can be unintuitive. There's a project called date-io that abstracts numerous date libraries. Please consider contributing to this project.

peacechen commented 3 years ago

I debugged this in the example project by supplying a selectedDate prop set to this.state.selectedDate initially undefined. When a date is selected, the onDateChange callback updates state and trickles back into CalendarStrip. However the prop update tried to clone startingDate but that prop is undefined. I've added a guard which will be published in 2.1.5.