【问题标题】:Getting an error while including breadcrumb in material-ui在 material-ui 中包含面包屑时出错
【发布时间】: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


【解决方案1】:

我认为你应该再次检查你的组件,错误是SelectInput.js:288 Uncaught TypeError: Cannot read property 'value' of undefined,所以你应该检查SelectInput.js中第288行传递给Select组件的value变量。您是否在组件中定义了一个名为 value 的变量?

【讨论】:

    猜你喜欢
    • 2020-03-23
    • 2019-10-22
    • 2020-08-07
    • 1970-01-01
    • 2022-09-23
    • 1970-01-01
    • 1970-01-01
    • 2019-08-02
    • 2018-09-30
    相关资源
    最近更新 更多