Files
SnowLuma/.pnpm-store/v11/files/4f/1e6bca2413e073788998526583e5d2a7fe37e0a4ea1e1b2c8e56d5d4863561facc8498d3c6104ef52879c8c3e065a9016fba3290d62be6a19b1faf8807568a
T
TanTan 2a69b23b47
Dev Build / cleanup (push) Waiting to run
Dev Build / typecheck (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

55 lines
2.3 KiB
Plaintext

import { RefObject } from "react";
import { App } from "../app.js";
/**
* React hook that automatically reports UI size changes to the host.
*
* Uses `ResizeObserver` to watch `document.body` and `document.documentElement` for
* size changes and sends `ui/notifications/size-changed` notifications.
*
* The hook automatically cleans up the `ResizeObserver` when the component unmounts.
*
* **Note**: This hook is rarely needed since the {@link useApp `useApp`} hook automatically enables
* auto-resize by default. This hook is provided for advanced cases where you
* create the {@link App `App`} manually with `autoResize: false` and want to add auto-resize
* behavior later.
*
* @param app - The connected {@link App `App`} instance, or null during initialization
* @param elementRef - Currently unused. The hook always observes `document.body`
* and `document.documentElement` regardless of this value. Passing a ref will
* cause unnecessary effect re-runs; omit this parameter.
*
* @example Manual App creation with custom auto-resize control
* ```tsx source="./useAutoResize.examples.tsx#useAutoResize_manualApp"
* function MyComponent() {
* // For custom App options, create App manually instead of using useApp
* const [app, setApp] = useState<App | null>(null);
* const [error, setError] = useState<Error | null>(null);
*
* useEffect(() => {
* const myApp = new App(
* { name: "MyApp", version: "1.0.0" },
* {}, // capabilities
* { autoResize: false }, // Disable default auto-resize
* );
*
* const transport = new PostMessageTransport(window.parent, window.parent);
* myApp
* .connect(transport)
* .then(() => setApp(myApp))
* .catch((err) => setError(err));
* }, []);
*
* // Add manual auto-resize control
* useAutoResize(app);
*
* if (error) return <div>Connection failed: {error.message}</div>;
* return <div>My content</div>;
* }
* ```
*
* @see {@link App.setupSizeChangedNotifications `App.setupSizeChangedNotifications`} for the underlying implementation
* @see {@link useApp `useApp`} which enables auto-resize by default
* @see {@link App `App`} constructor for configuring `autoResize` option
*/
export declare function useAutoResize(app: App | null, elementRef?: RefObject<HTMLElement | null>): void;