1

I am trying to have GoogleMapGazi access the props of my class GoogleMaps using the 'props=> ' but I cannot do it. I have passed the lat and lng props to the class by the parent component. Here's my code, any help will be great!

const GoogleMapGazi = withGoogleMap(props => (
  <GoogleMap
    defaultCenter={{ lat: 25.804281, lng: -80.1903893 }}
    defaultZoom={15}
  >
    <Marker position={{ lat: props.lat, lng: props.lng }} />
  </GoogleMap>
));

class GoogleMaps extends Component {
  render() {
    return (
      <div>
        <GoogleMapGazi
          containerElement={<div style={{ height: `500px`, width: "600px" }} />}
          mapElement={<div style={{ height: `100%` }} />}
        />
      </div>
    );
  }
}

export default GoogleMaps;
2
  • You are not passing the lat and lng props to the GoogleMapGazi component in the GoogleMaps parent component. Commented Aug 2, 2018 at 17:56
  • Why are you doing props.lat? GoogleMapGazi doesn't have the prop lat and lng defined, why would you expect them to be magically defined in your GoogleMapGazi? Commented Aug 2, 2018 at 17:57

1 Answer 1

1

You have to pass down the props from the GoogleMaps component.

You could explicitly pass down the lat and lng props, or you can use the spread syntax to pass down all props.

class GoogleMaps extends Component {
  render() {
    return (
      <div>
        <GoogleMapGazi
          containerElement={<div style={{ height: `500px`, width: "600px" }} />}
          mapElement={<div style={{ height: `100%` }} />}
          {...this.props}
        />
      </div>
    );
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

You sir are awesome! Thank you very much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.