0
我正在开发一个简单的模态和一些工具提示。我想了解一些门户网站,因此决定着手制作一个门户网站。我有以下代码:创建一个ReactJS门户
const Portal = React.createClass({
render() { return null },
portalElement: null,
componentDidMount() {
let p = this.props.portalId && document.getElementById(this.props.portalId);
if(!p) {
let p = document.createElement('div');
p.id = this.props.portalId;
document.body.appendChild(p);
}
this.portalElement = p;
this.componentDidUpdate();
},
componentWillUnmount() {
document.body.removeChild(this.portalElement);
},
componentDidUpdate() {
render(<div {...this.props}>{this.props.children}</div>, this.portalElement);
}
});
当我运行这段代码,我得到以下错误控制台:
Uncaught Error: _registerComponent(...): Target container is not a DOM element.
我的理解是,它无法找到的元素,其中在体内安装这种。我曾尝试添加到index.html,但这仍然没有解决它。
感谢您的帮助。
选中此http://stackoverflow.com/questions/28802179/how-to-create-a-react-modalwhich-is - 带转换的身体碰撞 –
@GinoLlerena感谢您的快速响应。我遵循那个教程 - 多数民众赞成在上面的代码。 –