我想通过块拆分我的React应用程序并遇到问题。 React.Component
不会渲染通过require.ensure
加载的子代码React.Component
。下面的示例代码。
文件之一:
异步React.Component不会为我工作
let Child;
class Parent extends React.Component {
constructor() {
super();
require.ensure(['child'],() => {
Child = require('child');
});
}
render() {
return (
<div>
{!!Child && <Child/>}
</div>
);
}
}
文件中的两个
class Child extends React.Component {
render() {
return <div>hello world</div>;
}
}
module.exports = Child;
我检索下一个错误:
Uncaught Error: Minified React error #130; visit http://facebook.github.io/react/docs/error-decoder.html?invariant=130&args[]=undefined&args[]= for the full message or use the non-minified dev environment for full errors and additional helpful warnings.
谁能告诉我什么,我做错了什么?
我已经采纳了您的建议,现在我将'Child'组件存储到'store'中。但是我面临另一个问题_Uncaught TypeError:无法读取' '中undefined_的属性'状态'。我认为这个问题发生在捆绑缩小之后。 –
这是一个核心React/Javascript功能。你的设置有些不正确,可能是在你的编译器/缩小器中,它不在你粘贴的任何代码中,而且我们很难识别。 –