import React, { Component } from 'react';
import { createPortal } from 'react-dom';
export default class Dialog extends Component {
constructor(props) {
super(props);
const doc = window.document;
this.node = doc.createElement('div');
doc.body.appendChild(this.node);
}
componentWillUnmont(){
window.document.body.removeChild(this.node);
}
render(){
const { hideDialog } = this.props;
return createPortal(
<div>
{this.props.children}
{typeof hideDialog === 'function' && (
<button onClick={ hideDialog }>关闭</button>
)
</div>, this.node
)
}
}
React-Protal(传送门)
猜你喜欢
转载自blog.csdn.net/qq_36162529/article/details/102682926
今日推荐
周排行