【发布时间】:2018-10-29 21:35:37
【问题描述】:
我在文件 ./MyInput.react.js 中有以下 ReactJs 组件
import React from 'react';
export default class MyInput extends React.Component {
constructor(props) {
super(props);
this.id = getNextId();
this.onChange = this.onChange.bind(this);
}
onChange(e) {
this.props.onChange(e.target.value);
}
render() {
return (
<label htmlFor={this.id}>
{this.props.label}
<input
id={this.id}
value={this.props.value}
onChange={this.onChange}
/>
</label>
);
}
}
现在我尝试像这样将它导入 ./index.js:
import {MyInput} from './MyInput.react';
控制台返回错误:
Error: Minified React error #130
你刚才遇到的错误全文是:
Element type is invalid: expected a string (for built-in components) or
a class/function (for composite components) but got: undefined.
这有什么问题?
【问题讨论】:
-
如果你搜索那个错误,你会发现超过 50 个 SO 结果,Link。所以不需要添加新的问题和答案:)
-
你是对的。每个问题在某种形式的某个地方都有一个答案。对于我的案例,我没有找到对异常“错误:缩小反应错误 #130”的快速直接解释。因此,我认为这个解释会帮助那些发现自己处于同样情况的人。
-
我遇到了这个错误,与类中作为 JSX.Element 的箭头函数有关。例如class myClass extends Component { CustomElement = () => { return } render() { return} } 在测试和调试中,没有什么可抱怨的。部署和发布时,它会崩溃并给出上面的错误。解决方案,渲染如下 customElement = () => { return } 解决方案...使用 {this.customElement() } 渲染它
标签: reactjs ecmascript-6 es6-class