Skip to content

Commit d139f0e

Browse files
committed
refactor(demo): init editor on specific textarea instead of first in dom
1 parent bab8644 commit d139f0e

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

packages/demo/src/App.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import React, { useEffect } from 'react'
1+
import React, { useEffect, useRef, useState } from 'react'
22

3-
import editor from '@mdx-live/editor'
3+
import mdxLiveEditor from '@mdx-live/editor'
44
import styled from 'styled-components'
55
import '@axe312/easymde/dist/easymde.min.css'
66

@@ -36,11 +36,22 @@ const replacements = {
3636
}
3737

3838
export default function App() {
39-
let easymde
39+
const editorRef = useRef(null)
40+
const [editor, setEditor] = useState(null)
4041

4142
useEffect(() => {
42-
easymde = editor({ components, replacements })
43-
}, [easymde])
44-
45-
return <Textarea id="editor" defaultValue={defaultMarkdownValue} />
43+
if (!editor) {
44+
setEditor(
45+
mdxLiveEditor({
46+
components,
47+
replacements,
48+
easymde: { element: editorRef.current }
49+
})
50+
)
51+
}
52+
})
53+
54+
return (
55+
<Textarea ref={editorRef} id="editor" defaultValue={defaultMarkdownValue} />
56+
)
4657
}

0 commit comments

Comments
 (0)