Update defaultCenter based on state
See original GitHub issueHow 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:
- Created 6 years ago
- Reactions:1
- Comments:6
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Or you can only use
center
props instead all of this (:I think
defaultCenter
andcenter
are in accordance with React’sdefaultValue
andvalue
properties, which are used in a lot of common places.