/
suhushinas
/
renderless-components-examples
Обзор
Документация
Войти
/
suhushinas
/
renderless-components-examples
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/modules/map/components/Map.jsx
43 строки
932 B
SuhushinAS
fix
24 апр 2019, 04:28
24 апр 2019, 04:28
3ef582a
Код
Авторство
О чём код?
import L from 'leaflet'; import 'modules/map/components/Map.css'; import {MapContext} from 'modules/map/context/MapContext.jsx'; import React from 'react'; class Map extends React.PureComponent { state = { isLoad: false, leaflet: undefined, }; constructor(props) { super(props); this.map = React.createRef(); } handleLoad = () => { this.setState({isLoad: true}); }; render() { return ( <div className="map" ref={this.map}> <MapContext.Provider value={this.state}> {this.state.leaflet && this.props.children} </MapContext.Provider> </div> ); } componentDidMount() { const leaflet = L.map(this.map.current); this.setState({leaflet}); window.addEventListener('load', this.handleLoad); } componentWillUnmount() { this.state.leaflet.remove(); window.removeEventListener('load', this.handleLoad); } } export default Map;