# IME composition {#ime}

Source: [Prevent interrupted IME input in React contentEditable · Yurich](https://leeyujoo.com/yurich/features/ime/)

Package: [`yurich`](https://www.npmjs.com/package/yurich)

Package version: `0.1.2`

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

## Try it {#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.

## Add it to your editor {#setup}

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.

```tsx
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 {#behavior}

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](https://leeyujoo.com/yurich/#restore-a-draft).

[Features](https://leeyujoo.com/yurich/features/)
