简体   繁体   English

从 mui v4 迁移到 v5 | TypeError:无法读取未定义的属性(读取“keyboardDate”)

[英]Migrating from mui v4 to v5 | TypeError: Cannot read properties of undefined (reading 'keyboardDate')

Hello after updating the MUI v4 to version v5 i got faling test's that's looking like this你好,在将 MUI v4 更新到版本 v5 后,我得到了错误测试,看起来像这样

    TypeError: Cannot read properties of undefined (reading 'keyboardDate')

      17 |   it("should render correctly without any errors", () => {
      18 |     expect(
    > 19 |       renderer.create(<DatePickerElement onChange={onChange} value="10/08/1981" />).toJSON(),
         |                ^
      20 |     ).toMatchSnapshot();
      21 |   });
      22 |   // props testing

I've done i think everything according to the guide migration and can't think of reason why this faling the component is wrapped with new <LocalizationProvider dateAdapter={AdapterDateFns} utils={DateFnsUtils}> and working fine only the test's are faling at render method did any one encountred similiar issue?我已经根据指南迁移完成了我认为的所有事情,并且想不出为什么这个失败的组件被新的<LocalizationProvider dateAdapter={AdapterDateFns} utils={DateFnsUtils}>并且工作正常只有测试失败的原因渲染方法是否有人遇到过类似的问题?

it("should render correctly without any errors", () => {
expect(
  renderer
    .create(<DatePickerElement onChange={onChange} value="10/08/1981" />)
    .toJSON(),
).toMatchSnapshot();  });

With the new migration, some Datepicker dependencies seem to be unstable or incompatible, and I find the official mui documentation doesn't do a good job of specifying compatible versions.随着新的迁移,一些 Datepicker 依赖项似乎不稳定或不兼容,我发现官方 mui 文档在指定兼容版本方面做得不好。 Still, these docs provide additional info about the pickers migration from @material-ui to @mui.不过,这些文档提供了有关从 @material-ui 到 @mui 的选择器迁移的其他信息。

I ran into the undefined keyboardDate issue and solved it by installing these specific versions of dependencies:我遇到了未定义的 keyboardDate 问题并通过安装这些特定版本的依赖项解决了它:

Dependencies I used:我使用的依赖项:

"@date-io/date-fns": "^1.3.13",
"@date-io/moment": "^1.3.13",
"date-fns": "^2.23.0",
"@mui/x-date-pickers": "^5.0.10",
"@mui/lab": "^5.0.0-alpha.112",

Imports: Please remember to import LocalizationProvider, AdapterDateFns, DatePicker from @mui/x-date-pickers , as @mui/lab v5 moved their locations.导入:请记住从@mui/x-date-pickers pickers 导入 LocalizationProvider、AdapterDateFns、DatePicker,因为 @mui/lab v5 移动了它们的位置。

Snippet:片段:

<LocalizationProvider dateAdapter={AdapterDateFns} utils={MomentUtils}>
  <DatePicker 
    label='Start Date'
    value={value}
    onChange={handleChange}
    inputFormat="mm/dd/yyyy"
    renderInput={(params) => <TextField {...params} />}
  />
</LocalizationProvider>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError:无法读取未定义的属性(读取“v”) - TypeError: Cannot read properties of undefined (reading 'v') 类型错误:无法读取未定义的属性“v4” - TypeError: Cannot read property 'v4' of undefined (MUI 文本字段)未捕获的 TypeError:无法读取未定义的属性(读取“焦点”) - (MUI Textfield) Uncaught TypeError: Cannot read properties of undefined (reading 'focus') MUI 警报未捕获类型错误:无法读取未定义的属性(读取“光”) - MUI Alert Uncaught TypeError: Cannot read properties of undefined (reading 'light') v-on 处理程序中的错误:“TypeError:无法读取未定义的属性(读取'输入') - Error in v-on handler: "TypeError: Cannot read properties of undefined (reading 'input') TypeError:无法在 discord.js v13 中读取未定义的属性(读取“路径”) - TypeError: Cannot read properties of undefined (reading 'path') in discord.js v13 TypeError:降级到 react-scripts v4.0.3 后无法读取未定义的属性(读取“原型”) - TypeError: Cannot read properties of undefined (reading 'prototype') after downgrading to react-scripts v4.0.3 错误 discord.js v14(类型错误:无法读取未定义的属性(读取“标志”)) - Erro discord.js v14 (TypeError: Cannot read properties of undefined (reading 'FLAGS')) MUI:从material v4升级到v5后,提供的`styles`参数无效 - MUI: The `styles` argument provided is invalid after upgrading from material v4 to v5 MUI v5 中未定义自动完成的默认值 - Default value of Autocomplete is undefined in MUI v5
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM