19 / 24
19
useEditorAPI

High-level programmatic control

A hook that provides non-reactive getter functions for reading and writing editor content without dispatching low-level actions.

Toolbar.tsx
import { useEditorAPI } from "@/hooks/useEditorAPI"

function Toolbar() {
  const api = useEditorAPI()

  const handleSave = () => {
    const html = api.getHTML()
    const md   = api.getMarkdown()
    const json = api.getJSON()
    const text = api.getPlainText()
    saveToDB({ html, md, json, text })
  }

  const handleClear = () => api.clear()

  const handleLoad = (content) => {
    api.setContent(content)
  }

  return (
    <>
      <button onClick={handleSave}>Save</button>
      <button onClick={handleClear}>Clear</button>
    </>
  )
}
MethodReturnsDescription
getJSON()ContainerNodeGet the raw node tree as JSON
getHTML()stringSerialize content to HTML
getMarkdown()stringSerialize content to Markdown
getPlainText()stringGet content as plain text
setContent(container)voidReplace entire editor content
insertBlock(node)voidInsert a block at the current cursor position
clear()voidClear all editor content
Documentation | Mina Rich Editor