Answer the question
In order to leave comments, you need to log in
How to update only children in react?
I'm passing checkpoints to a map that shouldn't be updated because it's canvas. But at the same time, the number of checkpoints should change. If I turn on the map update when the number of checkpoints changes, then I will get a lot of errors associated with re-assigning elements to the map. And how then to update only this.props.children in the map, but not touch the rest?
class MapController extends Component<MapControllerProps> {
shouldComponentUpdate() {
return false;
}
render() {
return (
<div id="map-container">
<Map
style="mapbox://styles/mapbox/streets-v8"
containerStyle={{
height: '100%',
width: '100%'
}}
center={[car3DModelLayer.coordinates.lat, car3DModelLayer.coordinates.lng]}
zoom={[17]}
pitch={[65]}
bearing={[20]}
onZoom={this.zoomControl}
onStyleLoad={this.props.onStyleLoad}
onMouseMove={this.props.onMouseMove}
>
<div>{this.props.children}</div>
<MapContext.Consumer>
{(map: any): any => {
this.props.onLoad ? this.props.onLoad(map) : null;
}}
</MapContext.Consumer>
<ScaleControl position="top-right"/>
<BuildingsLayer3DComponent />
</Map>
</div>
);
}
}
class MapComponent extends Component<{}, MapComponentState> {
state = {
checkedCoordinates: { lng: 0, lat: 0 },
waypoints: [{lat: 24.03862, lng: 49.83498}]
}
render() {
return(
<div>
<MapController waypoints={this.state.waypoints} onStyleLoad={this.handleMapStyleClick} onLoad={this.handleMapLoad} getCoords={this.getCoords}>
<Checkpoint textColor="#ffffff" icon="map-marker-icon" iconScale={0.15} points={this.state.waypoints} />
</MapController>
<RoutingForm handleClick={this.addWaypoint} lat={this.state.checkedCoordinates.lat} lng={this.state.checkedCoordinates.lng} />
</div>
);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question