UNPKG

rc-bmap

Version:

<p align="center"> <img src="https://bmap.jser-club.com/home.png" width="200px"> </p> <p align="center">基于 React 的百度地图组件</p>

49 lines (40 loc) 964 B
import { PureComponent } from 'react'; import ReactDOM from 'react-dom'; import PropTypes from 'prop-types'; class HTMLComponent extends PureComponent { static contextTypes = { centralizedUpdates: PropTypes.func, } static displayName = 'HTMLComponent'; constructor(props) { super(props); this.div = document.createElement('div'); } componentDidMount() { const { context } = this; ReactDOM.render(this.props.children, this.div); context.centralizedUpdates({ name: this.name, data: this.div, }); } componentDidUpdate() { const { context } = this; ReactDOM.render(this.props.children, this.div); context.centralizedUpdates({ name: this.name, data: this.div, }); } componentWillUnmount() { const { context } = this; context.centralizedUpdates({ name: this.name, data: null, }); } render() { return null; } } export default HTMLComponent;