【发布时间】:2020-05-26 17:56:25
【问题描述】:
我使用的是 material-ui/core 版本 3.9.0。 &反应版本 16.13.1。
但是,需要包含面包屑。将 material-ui 包更新为 4.0.2。但是,当应用程序编译时没有错误。应用加载时出错。 错误如下-
SelectInput.js:288 Uncaught TypeError: Cannot read property 'value' of undefined
at SelectInput.js:288
at Array.map (<anonymous>)
at SelectInput.js:287
at commitHookEffectListMount (react-dom.development.js:19731)
at commitPassiveHookEffects (react-dom.development.js:19769)
at HTMLUnknownElement.callCallback (react-dom.development.js:188)
at Object.invokeGuardedCallbackDev (react-dom.development.js:237)
at invokeGuardedCallback (react-dom.development.js:292)
at flushPassiveEffectsImpl (react-dom.development.js:22853)
at unstable_runWithPriority (scheduler.development.js:653)
在调试模式下,错误位于以下文件中 - node_modules/@material-ui/core/esm/Select/SelectInput.js 文件错误显示为
React.useEffect(function () {
if (!foundMatch && !multiple && value !== '') {
var values = React.Children.toArray(children).map(function (child) {
return child.props.value;
});
console.warn(["Material-UI: you have provided an out-of-range value `".concat(value, "` for the select ").concat(name ? "(name=\"".concat(name, "\") ") : '', "component."), "Consider providing a value that matches one of the available options or ''.", "The available values are ".concat(values.filter(function (x) {
return x != null;
}).map(function (x) {
return "`".concat(x, "`");
}).join(', ') || '""', ".")].join('\n'));
}
}, [foundMatch, children, multiple, name, value]);
<Select
className={`clientSelector selectCombo ${classNames}`}
value={value}
renderValue={(value) =>
items.find((d) => d.clientId == value).name
}
onChange={(e) => this.valueSelected(e)}
disabled={clientDisabled}
>
{items.map((item, i) => {
return (
<MenuItem key={i} value={item.clientId}>
{item.name}
</MenuItem>
);
})}
</Select>
【问题讨论】:
-
请出示您的
Select的代码。 -
感谢瑞恩的回复。页面上的选择代码是-
标签: reactjs material-ui