[英]react18 + react-datepicker@4.8.0(node18) can not display component Datepicker
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.错误:元素类型无效:应为字符串(对于内置组件)或类/函数(对于复合组件)但得到:object。
I just make on example from documentation, but I get an error that above:我只是从文档中举个例子,但我得到了上面的错误:
import React, { useState } from 'react';
import DatePicker from 'react-datepicker';
import 'react-datepicker/dist/react-datepicker.css';
const Example = () => {
const [startDate, setStartDate] = useState(new Date());
return (
<DatePicker
selected={startDate}
onChange={(date: Date) => setStartDate(date)}
/>
);
};
maybe someone faced a similar problem, I will be grateful for help也许有人遇到过类似的问题,我将不胜感激
there is no issue in the 'react-datepicker' package. I have checked the above code it is working correctly. 'react-datepicker' package 没有问题。我已经检查了上面的代码它是否正常工作。
I also faced the same issue so when I checked my code I had written one function outside the primary function. So that's why this issue comes you can check your other file code.我也遇到了同样的问题,所以当我检查我的代码时,我在主要的 function 之外写了一个 function。所以这就是为什么出现这个问题你可以检查你的其他文件代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.