Skip to content

Vizel API / react/src / useVizelMarkdown

Function: useVizelMarkdown()

ts
function useVizelMarkdown(editor, options?): UseVizelMarkdownResult;

Defined in: packages/react/src/hooks/useVizelMarkdown.ts:79

React hook for bidirectional Markdown synchronization with the editor.

Parameters

ParameterTypeDescription
editorEditor | null | undefinedThe editor instance, or null/undefined while it is still initializing.
optionsUseVizelMarkdownOptionsSync options

Returns

UseVizelMarkdownResult

Markdown state and control functions

Examples

tsx
import { useVizelEditor, useVizelMarkdown } from '@vizel/react';

function App() {
  const editor = useVizelEditor();
  const { markdown, setMarkdown, isPending } = useVizelMarkdown(editor, {
    debounceMs: 300,
  });

  return (
    <div>
      <VizelEditor editor={editor} />
      <textarea
        value={markdown}
        onChange={(e) => setMarkdown(e.target.value)}
      />
      {isPending && <span>Syncing...</span>}
    </div>
  );
}
tsx
// With initial markdown value
const { markdown, setMarkdown } = useVizelMarkdown(editor, {
  initialValue: "# Hello World",
  transformDiagrams: true,
});

Released under the MIT License.