Skip to content

Commit 9c9b022

Browse files
committed
feat(website):加loading
1 parent cadd79b commit 9c9b022

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

website/src/components/useMdData/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ const useMdData = (path: (lang: string) => Promise<{ default: CodeBlockData }>,
1111
languages: {},
1212
});
1313
const lang = init.t(name);
14+
15+
const [loading, setLoading] = useState(false);
1416
useEffect(() => {
17+
setLoading(() => true);
1518
const getMd = async () => {
1619
try {
1720
const result = await path(lang);
@@ -21,10 +24,12 @@ const useMdData = (path: (lang: string) => Promise<{ default: CodeBlockData }>,
2124
} catch (err) {
2225
console.warn(err);
2326
}
27+
setLoading(() => false);
2428
};
2529
getMd();
26-
}, [lang, path]);
27-
return mdData;
30+
// eslint-disable-next-line react-hooks/exhaustive-deps
31+
}, [lang]);
32+
return { mdData, loading };
2833
};
2934

3035
export default useMdData;

website/src/pages/docs/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import MarkdownPreview from '@uiw/react-markdown-preview';
22
import useMdData from './../../components/useMdData';
3+
import { Loader } from 'uiw';
34
export function HomePage() {
4-
const mdData = useMdData((path) => {
5+
const { mdData, loading } = useMdData((path) => {
56
return import(`markdown-react-code-preview-loader/README${path}.md`);
67
});
7-
return <MarkdownPreview source={mdData.source} />;
8+
return (
9+
<Loader style={{ width: '100%' }} loading={loading} tip="loading...">
10+
<MarkdownPreview source={mdData.source} />
11+
</Loader>
12+
);
813
}

website/src/pages/example/index.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import MarkdownPreview from '@uiw/react-markdown-preview';
22
import PreView from '../../components/CodeLayout';
33
import useMdData from './../../components/useMdData';
4+
import { Loader } from 'uiw';
5+
46
const getMetaData = (meta: string) => {
57
if (meta) {
68
const [metaItem] = /mdx:(.[\w|:]+)/i.exec(meta) || [];
@@ -14,9 +16,9 @@ const getMetaData = (meta: string) => {
1416
};
1517

1618
export function ExamplePage() {
17-
const mdData = useMdData((path) => import(`./App${path}.md`));
19+
const { mdData, loading } = useMdData((path) => import(`./App${path}.md`));
1820
return (
19-
<div>
21+
<Loader style={{ width: '100%' }} loading={loading} tip="loading...">
2022
<MarkdownPreview
2123
source={mdData.source}
2224
components={{
@@ -50,6 +52,6 @@ export function ExamplePage() {
5052
},
5153
}}
5254
/>
53-
</div>
55+
</Loader>
5456
);
5557
}

0 commit comments

Comments
 (0)