微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

重大UI日期选择器日历格式不正确

如何解决重大UI日期选择器日历格式不正确

想知道以前是否有人遇到过此问题。我试图从Material UI的选择器中简单实现DatePicker,并且不断看到日历的这种格式。在我看来,也许我的DateFnsUtils格式不正确,但是对于应该如何修复它我还是有些不满意。有人遇到过这个吗?

以下是一些规格:

"@date-io/date-fns": "^2.10.6" (Note I switched this back to 1.3.13 because of a kNown error)
"@material-ui/pickers": "^3.2.10"

这是我的代码(请注意,我使它成为要在其他地方使用的组件,但不应彻底改变结果):

import React,{ useState } from 'react';
import DateFnsUtils from '@date-io/date-fns'; // choose your lib
import PropTypes from 'prop-types';
import { muipickersutilsprovider,DatePicker as DatePickerComponent } from '@material-ui/pickers'

const DatePicker = ({
  defaultValue,variant,onChange,...props
}) => {
  const [selectedDate,setSelectedDate] = useState(defaultValue);

  const handleDateChange = (date) => {
    onChange(date);
    setSelectedDate(date);
  };

  return (
    <muipickersutilsprovider utils={DateFnsUtils}>
      <DatePickerComponent
        variant={variant}
        value={selectedDate}
        onChange={handleDateChange}
        {...props}
      />
    </muipickersutilsprovider>
  )
}

// Specifies the default values for props:
DatePicker.defaultProps = {
  defaultValue: new Date(),variant: 'inline',};

DatePicker.propTypes = {
  onChange: PropTypes.func.isrequired,defaultValue: PropTypes.object,variant: PropTypes.string,};

export default DatePicker

谢谢。

enter image description here

编辑: 我在故事书中构建了该组件,并且组件本身运行良好...

enter image description here

现在,我想知道将其作为组件导入时是否需要特殊功能

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。