-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Using fitView with resizable container #1419
Comments
I achieved this behaviour by adding a Edit: |
@pjaspinski do you have a code snippet for the same? I am trying to do something similar (resize my chart as my window resizes) and would be of help to me |
I don't have access to the codebase that I was working on when I created this issue, but I guess, that it was something along these lines: const Component = () => {
const {width, height} = useStore(sizeSelector);
useEffect(() => {
fitView();
}, [width, height]);
return ...;
}; Just check what is the structure of this lib's internal state and prepare |
I've been searching for this answer for months, and at long last, here it is. In Typescript: const widthSelector = (state: { width: any }) => state.width;
const heightSelector = (state: { height: any }) => state.height;
const reactFlowWidth = useStore(widthSelector);
const reactFlowHeight = useStore(heightSelector);
useEffect(() => {
reactFlowInstance.fitView();
}, [reactFlowWidth, reactFlowHeight, reactFlowInstance]); |
Hi, I stumbled upon a problem when using ReactFlow with React-RND.
React-RND provides a resizable component, in which I want to place a ReactFlow diagram.
Here is a sandbox. You can drag the dark border to resize the container and see the issue.
Implementation
When user stops resizing the component, the
onResizeStop
event is fired. I use it to set updated container dimensions to the state.This state is then passed as props to the component containing ReactFlow diagram.
These are then used to set dimensions of a div containing the diagram.
In the diagram component there is also a
useEffect
that callsfitView
when these props change.Problem
It seems that
fitView
always uses dimensions from before the last resizing. I couldn't find a solution that would fully fix it. Is there a way to force it to use updated dimensions? Or is it a problem withfitView
's implementation?I would really appreciate any help on this one.
The text was updated successfully, but these errors were encountered: