Skip to content

Vizel API / react/src / useVizelState

Function: useVizelState() ​

ts
function useVizelState(editor): number;

Defined in: packages/react/src/hooks/useVizelState.ts:33

Hook that forces a re-render whenever the editor's state changes.

This is useful for components that need to reflect the current editor state (e.g., formatting buttons that show active state). Backed by useSyncExternalStore plus createVizelEditorTransactionStore from @vizel/core so the subscription and version tracking are shared with the Vue and Svelte adapters.

Parameters ​

ParameterTypeDescription
editorEditor | null | undefinedThe editor instance (or null while it is still initializing)

Returns ​

number

A monotonically increasing transaction tick (typically ignored)

Example ​

tsx
function FormattingButtons({ editor }: { editor: Editor }) {
  useVizelState(editor);
  return (
    <button className={editor.isActive("bold") ? "active" : ""}>
      Bold
    </button>
  );
}

Released under the MIT License.