@mocanvas/mocanvas · function

useDefaultHelpers

declare function useDefaultHelpers(): {
    addToast: (toast: Omit<TLUiToast, "id"> & {
        id?: string;
    }) => string;
    removeToast: (id: string) => void;
    clearToasts: () => void;
    addDialog: (dialog: Omit<TLUiDialog, "id"> & {
        id?: string;
    }) => string;
    removeDialog: (id: string) => void;
    clearDialogs: () => void;
    announce: (value: TLUiA11y) => void;
    msg: (id: TLUiTranslationKey) => string;
    /** Open the editor's file picker and drop what is chosen onto the page. */
    insertMedia: () => void;
}

Everything a menu item's onSelect normally reaches for, in one object.

A menu item that wants to raise a toast, open a dialog, announce something or resolve a string would otherwise call four hooks — and could not, because an item is data rather than a component. Bundling them is what lets an action be defined as a plain function that takes these.

mocanvas is built by Symbio. Free for non-commercial, non-profit and development use; commercial use needs an agreement. Not affiliated with or endorsed by tldraw.