|
1 | | -import React, { useState, createRef, useRef, useImperativeHandle } from 'react'; |
| 1 | +import React, { useState, useRef, useImperativeHandle } from 'react'; |
2 | 2 | import { markdown, markdownLanguage } from '@codemirror/lang-markdown'; |
3 | 3 | import { languages } from '@codemirror/language-data'; |
4 | 4 | import { EditorView } from '@codemirror/view'; |
@@ -39,7 +39,7 @@ export interface IMarkdownEditor extends ReactCodeMirrorProps { |
39 | 39 | } |
40 | 40 |
|
41 | 41 | export interface ToolBarProps { |
42 | | - editor?: React.RefObject<ReactCodeMirrorRef>; |
| 42 | + editor: React.RefObject<ReactCodeMirrorRef>; |
43 | 43 | preview: React.RefObject<MarkdownPreviewRef>; |
44 | 44 | container: React.RefObject<HTMLDivElement>; |
45 | 45 | containerEditor: React.RefObject<HTMLDivElement>; |
@@ -72,15 +72,19 @@ function MarkdownEditor( |
72 | 72 | ...codemirrorProps |
73 | 73 | } = props; |
74 | 74 | const [value, setValue] = useState(props.value || ''); |
75 | | - const codeMirror = createRef<ReactCodeMirrorRef>(); |
| 75 | + const codeMirror = useRef<ReactCodeMirrorRef>(null); |
76 | 76 | const previewContainer = useRef<MarkdownPreviewRef>(null); |
77 | 77 | const container = useRef<HTMLDivElement>(null); |
78 | 78 | const containerEditor = useRef<HTMLDivElement>(null); |
79 | 79 |
|
80 | | - useImperativeHandle(ref, () => ({ |
81 | | - editor: codeMirror, |
82 | | - preview: previewContainer, |
83 | | - })); |
| 80 | + useImperativeHandle( |
| 81 | + ref, |
| 82 | + () => ({ |
| 83 | + editor: codeMirror, |
| 84 | + preview: previewContainer, |
| 85 | + }), |
| 86 | + [codeMirror, previewContainer], |
| 87 | + ); |
84 | 88 |
|
85 | 89 | const toolBarProps: ToolBarProps = { |
86 | 90 | editor: codeMirror, |
|
0 commit comments