Skip to content

Commit

Permalink
fix: 🐛 duplicate editor in strict mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Saul-Mirone committed Aug 6, 2022
1 parent 40d8340 commit 2f6c538
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/react/src/useGetEditor.ts
Expand Up @@ -26,6 +26,8 @@ export const useGetEditor = (getEditor: GetEditor) => {
const div = dom.current;
if (!div) return;

if (div.querySelector('.milkdown') != null) return;

const editor = getEditor(div, renderReact);
if (!editor) return;

Expand Down
4 changes: 2 additions & 2 deletions website/component/Demo/Demo.tsx
Expand Up @@ -6,7 +6,7 @@ import { i18nConfig, Local } from '../../route';
import { decode } from '../../utils/share';
import { Mode } from '../constant';
import { localCtx } from '../Context';
import { MilkdownEditor, MilkdownRef } from '../MilkdownEditor/MilkdownEditor';
import { MilkdownRef, OnlineEditor } from '../MilkdownEditor/OnlineEditor';
import { CodeMirror, CodeMirrorRef } from './CodeMirror';
import className from './style.module.css';

Expand Down Expand Up @@ -70,7 +70,7 @@ export const Demo = ({ mode }: DemoProps) => {
return !md.length ? null : (
<div ref={ref} className={classes}>
<div className={className['milk']}>
<MilkdownEditor ref={milkdownRef} content={md} onChange={milkdownListener} />
<OnlineEditor ref={milkdownRef} content={md} onChange={milkdownListener} />
</div>
<CodeMirror ref={codeMirrorRef} value={md} onChange={onCodeChange} lock={lockCode} />
</div>
Expand Down
Expand Up @@ -22,7 +22,7 @@ type Props = {
};

export type MilkdownRef = { update: (markdown: string) => void };
export const MilkdownEditor = forwardRef<MilkdownRef, Props>(({ content, readOnly, onChange }, ref) => {
export const OnlineEditor = forwardRef<MilkdownRef, Props>(({ content, readOnly, onChange }, ref) => {
const showToast = useContext(showToastCtx);
const isDarkMode = useContext(isDarkModeCtx);
const share = useContext(shareCtx);
Expand Down

1 comment on commit 2f6c538

@vercel
Copy link

@vercel vercel bot commented on 2f6c538 Aug 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.