question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Update defaultCenter based on state

See original GitHub issue

How can I update defaultCenter? I’ve tried editing map.props.defaultCenter by ref but this is a read-only property. The following code also doesn’t have any effects:

render() {
  <Location
    defaultCenter={this.state.defaultCenter}
    marker={{ position: { lat, lng } }}
  />
}
const Location = withGoogleMap(({ marker, defaultCenter }) => (
  <GoogleMap defaultCenter={{
    lat: marker.position.lat || defaultCenter.lat,
    lng: marker.position.lng || defaultCenter.lng
  }} />
));

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

18reactions
ammichaelcommented, Nov 9, 2017

Or you can only use center props instead all of this (:

4reactions
PowerOfMcommented, Sep 16, 2018

I think defaultCenter and center are in accordance with React’s defaultValue and value properties, which are used in a lot of common places.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Child component won't update with new props after setState
The error says exactly what's wrong, you can't change the defaults. Set defaultCenter once, then use your dynamic state variable on center ....
Read more >
A Beginner's Guide to google-map-react | by Matt Croak Code
I provide the defaultCenter which is where the map will be centered before it receives another option to change the center (in my...
Read more >
React Google Maps Style Guide
The live demos come with live updates by clicking the CODE button on the bottom-left ... Implement your own state transition logic with...
Read more >
Can I set a 'default center' value in react-googe-maps/api?
Coding example for the question Can I set a 'default center' value in ... How can I set the default state of a...
Read more >
Top 5 react-google-maps Code Examples - Snyk
Learn more about how to use react-google-maps, based on react-google-maps code ... </GoogleMap> )); interface State { defaultCenter: DefaultCenter | null;.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found