コマンドの実行と状態の購読
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 は名前でコマンドを実行し、isActive は選択範囲の書式を確認します。インスタンスは変わらないため、ツールバーはフックで必要な値を購読します。useEditorState では可能ならプリミティブ値を返します。