client: improve component render time

This commit is contained in:
fantasticit 2022-05-25 10:09:30 +08:00
parent 5e6f283032
commit d1f51707a8
3 changed files with 39 additions and 34 deletions

View File

@ -1,5 +1,5 @@
import { IconArticle, IconChevronLeft } from '@douyinfe/semi-icons';
import { Button, Nav, Popover, Skeleton, Space, Spin, Tooltip, Typography } from '@douyinfe/semi-ui';
import { IconChevronLeft } from '@douyinfe/semi-icons';
import { Button, Nav, Skeleton, Space, Spin, Tooltip, Typography } from '@douyinfe/semi-ui';
import { DataRender } from 'components/data-render';
import { Divider } from 'components/divider';
import { DocumentCollaboration } from 'components/document/collaboration';
@ -50,7 +50,9 @@ export const DocumentEditor: React.FC<IProps> = ({ documentId }) => {
});
}, [document, documentId]);
const actions = (
const actions = useMemo(
() =>
docAuthLoading ? null : (
<Space>
{document && authority.readable && (
<DocumentCollaboration key="collaboration" wikiId={document.wikiId} documentId={documentId} />
@ -60,6 +62,8 @@ export const DocumentEditor: React.FC<IProps> = ({ documentId }) => {
<DocumentStar key="star" documentId={documentId} />
<DocumentStyle />
</Space>
),
[docAuthLoading, documentId, document, authority]
);
useEffect(() => {

View File

@ -76,7 +76,8 @@ export const DocumentReader: React.FC<IProps> = ({ documentId }) => {
}, [document]);
const actions = useMemo(
() => (
() =>
docAuthLoading ? null : (
<Space>
{document && authority.readable && (
<DocumentCollaboration key="collaboration" wikiId={document.wikiId} documentId={documentId} />
@ -96,7 +97,7 @@ export const DocumentReader: React.FC<IProps> = ({ documentId }) => {
<DocumentStyle />
</Space>
),
[document, documentId, authority, gotoEdit]
[docAuthLoading, document, documentId, authority, gotoEdit]
);
const editBtnStyle = useMemo(() => getEditBtnStyle(isMobile ? 16 : 100), [isMobile]);

View File

@ -263,7 +263,7 @@ export const useWikiTocs = (wikiId) => {
const { data, error, refetch } = useQuery(
WikiApiDefinition.getTocsById.client(wikiId),
() => (wikiId ? getWikiTocs(wikiId) : null),
{ staleTime: 3000 }
{ staleTime: 2000 }
);
const loading = !data && !error;