PaulLeCam / react-leaflet

React components for Leaflet maps
https://react-leaflet.js.org
Other
5.13k stars 884 forks source link

could not get map and LayerContainer props in child component in version higher than 1.1.0 #305

Closed taozhi8833998 closed 7 years ago

taozhi8833998 commented 7 years ago

I build an simple app, with the following code

const map = (
  <Map center={center} zoom={13}>
    <Marker position={center}>
      <Popup>
        <span>Using marker </span>
      </Popup>
    </Marker>
    <TaoZhiLayer  />
  </Map>
)

TaoZhiLayer is a simple compent as below shows

class TaoZhiLayer extends Component {
  render() {
    console.log('this.props====', this.props)
    return  <div>taozhi</div>
  }
}

in TaoZhiLayer I could not get map and layerContanier properties in props, while I can get them in version 1.1.0, anyone has met this issue??? if it not issue, how could I get them in my component when I installed react-leaflet version higher than 1.1.0

PaulLeCam commented 7 years ago

These values are provided by the context, not the props, see this section of the documentation

taozhi8833998 commented 7 years ago

ok, thx, it works. Further more, I have seen this from react official website

If you want your application to be stable, don't use context. It is an experimental API and it is likely to break in future releases of React.

Thanks for ur help!

mikew commented 7 years ago

Quite shifty changing this in a bugfix release