React
Use 82editor as a React component.
npm i @82editor/core @82editor/reactimport { 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
valueandonChangelike a controlled input; changingvaluefrom outside updates the editor. - Every other prop is an option.
refgives 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>
</>
);
}