Create a simple editor component. The editor is created with createYooptaEditor({ plugins, marks });
import { useMemo, useEffect } from 'react';import YooptaEditor, { createYooptaEditor } from '@yoopta/editor';import Paragraph from '@yoopta/paragraph';import { Bold, Italic, Underline } from '@yoopta/marks';const plugins = [Paragraph];const marks = [Bold, Italic, Underline];export default function MyEditor() { const editor = useMemo(() => createYooptaEditor({ plugins, marks }), []); useEffect(() => { // Set initial content (or load from API/localStorage) editor.setEditorValue({}); }, [editor]); const onChange = (value) => { // Save to backend, localStorage, etc. console.log('Content:', value); }; return ( <div style={{ padding: '20px', maxWidth: '900px', margin: '0 auto' }}> <YooptaEditor editor={editor} onChange={onChange} placeholder="Type something..." /> </div> );}
The editor instance should be created with useMemo so it is not recreated on every render.
Plugins and marks are passed to createYooptaEditor, not to YooptaEditor. Use
editor.setEditorValue() for initial or loaded content and onChange to react to changes.
For a beautiful, ready-made design, apply a theme:
npm install @yoopta/themes-shadcn
import { applyTheme } from '@yoopta/themes-shadcn';import Paragraph from '@yoopta/paragraph';import { HeadingOne, HeadingTwo, HeadingThree } from '@yoopta/headings';import Blockquote from '@yoopta/blockquote';import { BulletedList, NumberedList } from '@yoopta/lists';import Code from '@yoopta/code';// Apply theme to plugins; CSS is imported automaticallyconst plugins = applyTheme([ Paragraph, HeadingOne, HeadingTwo, HeadingThree, Blockquote, BulletedList, NumberedList, Code,]);
Themes automatically apply styled components to your plugins. CSS styles are automatically imported when you import the theme package, so you don’t need to manually import any CSS files.You can still customize individual elements if needed.
Content is managed via the editor instance. Use editor.getEditorValue() to read and editor.setEditorValue(data) to set content. The onChange callback receives the same YooptaContentValue when the user edits: