Skip to main content
Version: 1.14.0

Search Highlight Plugin

import { useMemo } from "react";
import { withReact } from "slate-react";
import { withHistory } from "slate-history";

import { 
  createTazeEditor, 
  Taze,
  TDescendant
} from "@taze-editor/taze-core";

import { 
  createSearchHighlightPlugin,
  useSearchHighlightPluginStore
} from "@taze-editor/taze-plugin-search-highlight";

import { Toolbar } from "./Toolbar";

export default function App() {

  // NOTE: `useSearchHighlightPluginStore` 
  // Must be used for the search highlight plugin to work properly
  // This is a workaround for the fact that the plugin store does not
  // reflect the changes in the store to the editor
  const storeSearchHighlight = useSearchHighlightPluginStore();

  const editor = useMemo(() => 
    withReact(
      withHistory(
        createTazeEditor({
          plugins: [
            createSearchHighlightPlugin()
          ]
        })
      )
    ),
  []);

  const initialValue: TDescendant[] = [{
    type: "p",
    children: [{ text: "This is editable." }],
  }]

  return (
    <div>
      <Taze
        editor={editor} 
        initialValue={initialValue}
        beforeEditable={<Toolbar />}
      />
    </div>
  );
}