Skip to content

Commit c07188f

Browse files
committed
chore: modify example.
1 parent bf8922d commit c07188f

File tree

4 files changed

+49
-67
lines changed

4 files changed

+49
-67
lines changed

src/index.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import classnames from 'classnames';
2-
import * as React from "react";
2+
import React, { useState, createRef, useRef, useEffect } from 'react';
33
import { IProps } from './common/props';
44
import CodeMirror, { ICodeMirror } from './components/CodeMirror';
55
import MarkdownPreview, { MarkdownPreviewProps } from '@uiw/react-markdown-preview';
@@ -28,13 +28,13 @@ export default function MarkdownEditor(props: IMarkdownEditor) {
2828
visible = true,
2929
visibleEditor = true,
3030
previewProps = {}, ...codemirrorProps } = props;
31-
const [value, setValue] = React.useState(props.value || '');
32-
const codeMirror = React.createRef<CodeMirror>();
33-
const previewContainer = React.useRef<HTMLDivElement | null>()
34-
const [editor, setEditor] = React.useState<CodeMirror.Editor>();
35-
const container = React.useRef<HTMLDivElement>(null);
36-
const containerEditor = React.useRef<HTMLDivElement>(null);
37-
React.useEffect(() => {
31+
const [value, setValue] = useState(props.value || '');
32+
const codeMirror = createRef<CodeMirror>();
33+
const previewContainer = useRef<HTMLDivElement | null>()
34+
const [editor, setEditor] = useState<CodeMirror.Editor>();
35+
const container = useRef<HTMLDivElement>(null);
36+
const containerEditor = useRef<HTMLDivElement>(null);
37+
useEffect(() => {
3838
if (codeMirror.current) {
3939
setEditor(codeMirror.current.editor);
4040
}

website/App.tsx

Lines changed: 30 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import MarkdownEditor from '../';
22
import '@uiw/reset.css/reset.less';
3-
import * as React from 'react';
3+
import React, { useState } from 'react';
44
import DocumentStr from '../README.md';
55
import styles from './App.module.less';
66
import Footer from './components/Footer';
@@ -9,50 +9,35 @@ import MarkdownPreview from '@uiw/react-markdown-preview';
99
import Logo from './Logo';
1010

1111
const DocumentStrSource = DocumentStr.replace(/([\s\S]*)<!--dividing-->/, '').replace(/^\n*/g, '');
12-
13-
interface IAppState {
14-
mdstr: string;
15-
visible: boolean;
16-
}
17-
1812
let count = 1;
1913

20-
export default class App extends React.Component<any, IAppState> {
21-
constructor(props: any) {
22-
super(props);
23-
this.state = {
24-
mdstr: DocumentStrSource,
25-
visible: true,
26-
}
27-
}
28-
public render() {
29-
return (
30-
<div className={styles.warpper}>
31-
<GithubCorner fixed target="__blank" href="https://github.com/uiwjs/react-markdown-editor" />
32-
<div className={styles.logo}>
33-
<Logo />
34-
</div>
35-
<div className={styles.editor}>
36-
<button onClick={() => {
37-
count += 1;
38-
this.setState({ mdstr: `String ${count}` });
39-
}}>Modify Markdown</button>
40-
<button onClick={() => {
41-
this.setState({ visible: !this.state.visible })
42-
}}>{this.state.visible ? 'Show' : 'Hide'}</button>
43-
<MarkdownEditor
44-
visible={this.state.visible}
45-
options={{
46-
autofocus: true,
47-
showCursorWhenSelecting: true,
48-
}}
49-
height={500}
50-
value={this.state.mdstr}
51-
/>
52-
</div>
53-
<MarkdownPreview source={DocumentStrSource} className={styles.doc} />
54-
<Footer name="Kenny Wong" href="https://github.com/uiwjs/react-markdown-editor" github="https://github.com/uiwjs/react-markdown-editor" year={2019}/>
14+
export default function App() {
15+
const [visible, setVisible] = useState(true);
16+
const [mdstr, setMdstr] = useState<string>(DocumentStrSource);
17+
return (
18+
<div className={styles.warpper}>
19+
<GithubCorner fixed target="__blank" href="https://github.com/uiwjs/react-markdown-editor" />
20+
<div className={styles.logo}>
21+
<Logo />
5522
</div>
56-
);
57-
}
58-
}
23+
<div className={styles.editor}>
24+
<button onClick={() => {
25+
count += 1;
26+
setMdstr(`String ${count}`);
27+
}}>Modify Markdown</button>
28+
<button onClick={() => setVisible(!visible)}>{visible ? 'Show' : 'Hide'}</button>
29+
<MarkdownEditor
30+
visible={visible}
31+
options={{
32+
autofocus: true,
33+
showCursorWhenSelecting: true,
34+
}}
35+
height={500}
36+
value={mdstr}
37+
/>
38+
</div>
39+
<MarkdownPreview source={DocumentStrSource} className={styles.doc} />
40+
<Footer name="Kenny Wong" href="https://github.com/uiwjs/react-markdown-editor" github="https://github.com/uiwjs/react-markdown-editor" year={2019}/>
41+
</div>
42+
);
43+
}

website/declaration.d.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

website/react-app-env.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// <reference types="react-scripts" />
2+
3+
declare module '*.module.less' {
4+
const content: any;
5+
export default content;
6+
}
7+
8+
declare module '*.md' {
9+
const src: any;
10+
export default src;
11+
}

0 commit comments

Comments
 (0)