React/anu实现弹出层2

栏目: 服务器 · 发布时间: 8年前

内容简介:React/anu实现弹出层2

这次是使用了一个比较罕见的APIReactDOM.unstable_renderSubtreeIntoContainer,ReactDOM.unstable_renderSubtreeIntoContainer与ReactDOM.render 的区别是,一个能传parentContext,一个不能。

function  RealModal (props){
   return <div className='modal'>{props.children}</div>
}
  class Modal extends React.Component {
    appendMaskIntoDoc() {
        console.log(this)
        ReactDOM.unstable_renderSubtreeIntoContainer(
            this,
            <RealModal {...this.props}>
                {this.props.children}
            </RealModal>,
            this.container
        )
    }

    componentDidMount() {
      var div = this.container = document.createElement('div')
        div.innerHTML = '<p>1111</p><p>222</p>'
        div.className = 'placeholder'
        document.body.appendChild(div)
      
        this.appendMaskIntoDoc()
    }

    componentDidUpdate() {
        console.log('更新')
        this.appendMaskIntoDoc()
    }

    componentWillUnmount() {
        console.log('componentWillUnmount')
        document.body.removeChild(this.container)
    }

    render() {
        return null
    }
}
window.onload = function(){
    ReactDOM.render(<Modal title="aaa">99999</Modal>, document.getElementById('select'))

    setTimeout(function(){
       ReactDOM.render(<Modal title="aaa">新内容</Modal>, document.getElementById('select'))
    },500)
}

以上所述就是小编给大家介绍的《React/anu实现弹出层2》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

The Linux Programming Interface

The Linux Programming Interface

Michael Kerrisk / No Starch Press / 2010-11-6 / GBP 79.99

The Linux Programming Interface describes the Linux API (application programming interface)-the system calls, library functions, and other low-level interfaces that are used, directly or indirectly, b......一起来看看 《The Linux Programming Interface》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具