editor

React

Use 82editor as a React component.

npm i @82editor/core @82editor/react
import { useState } from 'react';
import { Editor82 } from '@82editor/react';
import '@82editor/core/styles.css';

export function WriteForm() {
  const [html, setHtml] = useState('');
  return <Editor82 value={html} onChange={setHtml} options={{ toolbar: 'board', height: 400 }} />;
}
  • Use value and onChange like a controlled input; changing value from outside updates the editor.
  • Every other prop is an option.
  • ref gives you the editor instance.
  • It is created after mount, so it is safe with SSR and Next.js.

Using the instance through ref

import { useRef } from 'react';
import { Editor82, type Editor } from '@82editor/react';

function Write() {
  const ref = useRef<Editor>(null);
  return (
    <>
      <Editor82 ref={ref} options={{ toolbar: 'board' }} />
      <button onClick={() => alert(ref.current?.getStats().chars)}>글자 수</button>
    </>
  );
}