Documentation

IME composition

Keep Korean, Japanese, and Chinese IME input intact when previewing HTML from a React contentEditable editor.

Try it

Switch to a Korean IME, type “한글” in the editor, and commit the composition. Check that the editor and HTML output both show “한글”. Yurich defers normalization during composition and reports the committed content to the preview.

Live example
Example result

Add it to your editor

Use onChange to update a separate HTML preview when typing Korean, Japanese, or Chinese text. If characters split apart mid-composition, check whether app code replaces the editable document during input. setHTML() replaces the document, so calling it after every change can also move the caret.

import { useState } from 'react';
import { EditorContent, EditorProvider, useEditor } from 'yurich';

export function CompositionEditor() {
  const [previewHTML, setPreviewHTML] = useState('');
  const editor = useEditor({ extensions: [], onChange: setPreviewHTML });

  return (
    <EditorProvider editor={editor}>
      <EditorContent ariaLabel="Editor" />
      <pre aria-label="HTML">{previewHTML}</pre>
    </EditorProvider>
  );
}

Behavior to account for

Keep initialValue for the first load. Pass onChange the state setter for the separate preview and reserve setHTML() for explicit actions like restoring a saved draft.

Features