-
Notifications
You must be signed in to change notification settings - Fork 935
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrapper component lifecycle issue #47
Comments
I see. Could you show me the reason why you'd like to read properties from a newly-changed |
Well, my use case actually involves reading shape data from a component that renders I suppose I could create a |
Related to #36 |
Just tried with your use case with react-google-maps/#basics/geolocation, yes, changing callback to However, I'm thinking that the same use case may apply for |
The |
Interesting. React definitely needs some kind of first-class "fragment" element that does not render anything to the DOM. I know they are working on it. In the mean time, have you looked at react-outlet? It could possibly be of interest here. Another interesting approach is the way MartyJS creates "container" components: calling |
Can we just ditch the extra This would solve this issue as well as the issue where we can't render any DOM elements as children of the Also, looking more closely at the code, I believe there is a memory leak in the current implementation, as the |
@idolize , could you please provide an example of Thanks! |
Yeah, my use case is I want to use my own DOM elements to replace some Google Maps controls. The Google Maps API allows you to do this for almost any control (such as the zoom indicator, panning buttons, drawing controls, etc.) Here is an example of how I could overwrite the drawing controls (which worked in the pre-wrapper component versions of this lib): import React from 'react';
import {DrawingManager} from 'react-google-maps';
export default React.createClass({
getInitialState() {
return { drawingMode: null };
},
setDrawingMode(drawingMode) {
this.setState({ drawingMode });
},
render () {
return (
<div>
<DrawingManager
{...this.props}
drawingControl={false} {/* Use our own buttons instead of the Google Maps built-in drawing control */}
drawingMode={this.state.drawingMode}
/>
<button onClick={this.setDrawingMode.bind(this, google.maps.drawing.OverlayType.CIRCLE)} className={this.state.drawingMode === google.maps.drawing.OverlayType.CIRCLE ? 'active' : ''}>Circle</button>
<button onClick={this.setDrawingMode.bind(this, google.maps.drawing.OverlayType.POLYGON)} className={this.state.drawingMode === google.maps.drawing.OverlayType.POLYGON ? 'active' : ''}>Polygon</button>
</div>
);
}
}); But this doesn't work with the current implementation because the new drawing controls I try to render don't show up, as they are rendered inside the virtual container div. The only way to get it to work with the current implementation involves duplicating state (in this case |
The
GoogleMaps
wrapper component breaks the React lifecycle because it does not re-render the VirtualContainer until after it is done updating everything.This means trying to get an updated value from a newly-changed
Marker
, for example, is not possible in any parent component'scomponentDidUpdate
method, because the children of the VirtualContainer are not yet re-rendered.This is a regression from the previous mixin/context methodology, and leads to very confusing and difficult to debug errors.
Perhaps one solution would be to re-render VirtualContainer on
componentWillUpdate
instead.The text was updated successfully, but these errors were encountered: