SheetXL - v0.8.0-beta.9+sites.210.e2d420901
    Preparing search index...

    Variable useModelListenerConst

    useModelListener: <SOURCE, EVENTS>(
        source: IListener.ISource<SOURCE> | null | undefined,
        listeners: IListener.Callbacks<SOURCE, EVENTS>,
        options?: ModelListenerOptions,
    ) => void

    React hook for subscribing to model-level events (workbooks, sheets, etc.).

    Type Declaration

      • <SOURCE, EVENTS>(
            source: IListener.ISource<SOURCE> | null | undefined,
            listeners: IListener.Callbacks<SOURCE, EVENTS>,
            options?: ModelListenerOptions,
        ): void
      • Type Parameters

        • SOURCE

          The model type (e.g., IWorkbook, ISheet)

        • EVENTS

          The listener interface type (e.g., ISheet.IListeners)

        Parameters

        • source: IListener.ISource<SOURCE> | null | undefined

          The model instance to listen to, or null to listen to nothing

        • listeners: IListener.Callbacks<SOURCE, EVENTS>

          Object containing listener callbacks for various events

        • Optionaloptions: ModelListenerOptions

          Optional configuration

        Returns void

    This hook automatically manages the listener lifecycle:

    • Subscribes when the component mounts or source changes
    • Unsubscribes when the component unmounts or source changes
    • Prevents unnecessary re-subscriptions when the listeners object reference changes (as long as the shape/keys remain consistent)

    By default (ignoreModelChange: false), all listeners are called once immediately on mount with the current source state, allowing you to initialize component state based on the model's current values.

    function SheetComponent({ sheet }: { sheet: ISheet }) {
    useModelListener<ISheet, ISheet.IListeners>(sheet, {
    onSave(source, json) {
    console.log('Sheet saved:', json);
    },
    });

    return <div>Sheet: {sheet.getName()}</div>;
    }