fitBounds doesn't get called on first render of graph, but it does in subsequent ones?
See original GitHub issuehi there!
here’s my code below. essentially I’m wrapping my graph in this ReactFlowComponent and my expectation was that it would automatically “fit bounds” everytime it lays out the elements. however, oddly, this doesnt seem to work for the first render, but it works for the subsequent ones.
any ideas on how to make this work? I suspect it might be that fitBounds is a no-op if there is no ReactFlow component yet?
const ReactFlowComponent = ({
elements,
width,
height,
}: {
elements: Array<Node | Edge>;
width: number | undefined;
height: number | undefined;
}) => {
// Fit the bounds of the laid-out graph to the size of the pane.
const { fitBounds, fitView } = useZoomPanHelper();
fitBounds({ x: 0, y: 0, width: width ?? 0, height: height ?? 0 });
return (
<ReactFlow
elements={elements}
nodeTypes={{
nodeWithFormulaOnHover: NodeWithFormulaOnHover,
}}
/>
);
};
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Mapbox fitBounds, function bounds map but does not render ...
Map bounds are get fit according to geojson, but problem is that when there is any marker on map and I try to...
Read more >Folium 0.12.1 documentation
Creates an Icon object that will be rendered using Leaflet.awesome-markers. Parameters. color (str, default 'blue') –. The color of the marker. You can...
Read more >Trimble Maps WebGL API Documentation
The Map object represents the map on your page. It exposes methods and properties that enable you to programmatically change the map, and...
Read more >Maps JavaScript API | Google Developers
Returns the lat/lng bounds of the current viewport. If more than one copy of the world is visible, the bounds range in longitude...
Read more >tomchentw/react-google-maps - Gitter
@tomchentw i'll fix first note then you can merge it ... @yhsiang Not sure if it's good paradigm to expose public function ......
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

I had this same problem and spent forever trying to figure it out. I tried adding it into
onLoadas the person above me suggested but it didn’t work.There was a recommendation buried somewhere deep in the issues in this repo that I tried out. I can’t take all the credit but I can’t find a reference to it at the moment. Here’s a snippet of what worked for me:
This is a simplified version of what I have, but it’s pretty straightforward. This is a second
useEffecton top of another one that I have which does something else.Thanks @datoslabs and @leejustin 😃 we will make it easier in v10 but for now this is the way to do it.