-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathEditor.tsx
More file actions
30 lines (24 loc) · 705 Bytes
/
Editor.tsx
File metadata and controls
30 lines (24 loc) · 705 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import 'prosemirror-view/style/prosemirror.css'
import './style/prosemirror.css'
import React, { useCallback, useEffect } from 'react'
import { useEditorView } from './EditorProvider'
export const Editor: React.FC<{ autoFocus?: boolean }> = React.memo(
({ autoFocus = false }) => {
const view = useEditorView()
const editorRef = useCallback(
(element: HTMLDivElement | null) => {
if (element) {
element.appendChild(view.dom)
}
},
[view]
)
useEffect(() => {
if (autoFocus) {
view.focus()
}
}, [autoFocus, view])
return <div ref={editorRef} className="prosemirror-editor" />
}
)
Editor.displayName = 'Editor'