Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

743 B
Raw Blame
/* Copyright 2026 Marimo. All rights reserved. */

import { useEffect } from "react";
import { useReactFlow, useStore } from "reactflow";
import { useDebouncedCallback } from "@/hooks/useDebounce";

/**
 * Call fitToView whenever the dimensions changes
 */
export function useFitToViewOnDimensionChange() {
  const instance = useReactFlow();
  const width = useStore(({ width }) => width);
  const height = useStore(({ height }) => height);
  const debounceFitView = useDebouncedCallback(() => {
    instance.fitView({ duration: 100 });
  }, 100);

  // When the window is resized, fit the view to the graph.
  useEffect(() => {
    if (!width || !height) {
      return;
    }
    debounceFitView();
  }, [width, height, debounceFitView]);
}