Run commands and connect controls
interface EditorInstance {
execute(command: string, value?: unknown): void;
isActive(commandOrName: string, value?: unknown): boolean;
}
const bold = useIsActive(editor, 'toggleBold');
const heading = useIsActive(editor, 'setHeading', 2);
const undoAvailable = useCanUndo(editor);
const redoAvailable = useCanRedo(editor);
const isEmpty = useEditorState(editor, e => (e.el?.textContent ?? '') === '');
execute runs a named command. isActive checks formatting at the selection. The instance is stable, so use the React hooks to subscribe to the values your toolbar displays. Return a primitive from useEditorState when the selected value is a boolean, string or number. Creating a new object each time causes extra renders.