picker 插件使用问题
当我在umi创建的react项目中,使用re-picker这个插件来添加时间选择器的时候,点击输入框,出现了以下问题:
PickerPanel.js:123 Uncaught TypeError: Cannot read property 'getNow' of undefined
devScripts.js:5931 The above error occurred in the <PickerPanel> component:
具体可以查看下面图片和视频
import styles from './index.less';
import Picker from 'rc-picker';
import 'rc-picker/assets/index.css';
export default function IndexPage() {
return (
<div>
<h1 className={styles.title}>Page index</h1>
<Picker />
</div>
);
}

https://user-images.githubusercontent.com/26154710/114566348-bfb7de80-9ca4-11eb-9723-6f81d6a23413.mov
I don't know if you still have issues with it but what I discovered about this issue is that the Date library (Moment/date-fns/dayjs) is not properly imported. To solve that, just import from one of the existing ones and pass as a prop the generateConfig such as:
import Picker from 'rc-picker';
import 'rc-picker/assets/index.css';
import momentGenerateConfig from 'rc-picker/lib/generate/moment'; // here
const MyPicker = () => <Picker generateConfig={momentGenerateConfig} />
Turns out that this leads to another issue with locale, so I also needed to import that and the final code looks similar to:
import Picker from 'rc-picker';
import 'rc-picker/assets/index.css';
import momentGenerateConfig from 'rc-picker/lib/generate/moment';
import enUS from 'rc-picker/lib/locale/en_US';
const MyPicker = () => <Picker generateConfig={momentGenerateConfig} locale={enUS} />
You can also look at some examples inside the examples dir 😄