calendar icon indicating copy to clipboard operation
calendar copied to clipboard

Uncaught TypeError: Cannot read property '0' of undefined

Open haldunanil opened this issue 7 years ago • 1 comments

I'm trying to use RangeCalendar inside Picker but I keep getting this error:

Uncaught TypeError: Cannot read property '0' of undefined
    at _class.getStartValue (RangeCalendar.js:671)
    at _class.render (RangeCalendar.js:169)
    at finishClassComponent (react-dom.development.js:13727)
    at updateClassComponent (react-dom.development.js:13690)
    at beginWork (react-dom.development.js:14489)
    at performUnitOfWork (react-dom.development.js:17014)
    at workLoop (react-dom.development.js:17054)
    at HTMLUnknownElement.callCallback (react-dom.development.js:149)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:199)
    at invokeGuardedCallback (react-dom.development.js:256)

My implementation looks like this:

import React from "react";

import * as moment from "moment";
import Picker from "rc-calendar/lib/Picker";
import RangeCalendar from "rc-calendar/lib/RangeCalendar";

interface RangePickerProps extends React.HTMLAttributes<HTMLElement> {}

const selected = [
  moment(),
  moment()
    .clone()
    .add(1, "months")
];

export const RangePicker: React.SFC<RangePickerProps> = (
  props: RangePickerProps
) => {
  const calendar = (
    <RangeCalendar
      defaultSelectedValue={selected}
      format="YYYY/MM/DD"
    />
  );

  const input = ({ value }) => <input value={value} />;

  return (
    <Picker calendar={calendar} {...props}>
      {input}
    </Picker>
  );
};

export default RangePicker;

I don't have the same issue when using the Calendar component from:

import Calendar from "rc-calendar/lib/Calendar";

Is my code missing something?

haldunanil avatar Mar 04 '19 23:03 haldunanil

I can reproduce the issue .. Anyone can look into it --->

https://codesandbox.io/embed/v36q3worl3

parthmakadiya12 avatar Mar 22 '19 08:03 parthmakadiya12