From e5c30aafa0c4aacd6f5f1351aba0f98e288c22ea Mon Sep 17 00:00:00 2001 From: infeng Date: Tue, 17 Sep 2019 14:41:39 +0800 Subject: [PATCH] feat: reduce render times --- src/ViewerCore.tsx | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/src/ViewerCore.tsx b/src/ViewerCore.tsx index 440e044..6fdc36a 100644 --- a/src/ViewerCore.tsx +++ b/src/ViewerCore.tsx @@ -114,6 +114,7 @@ export default (props: ViewerProps) => { return { ...s, activeIndex: action.payload.index, + startLoading: true, }; case ACTION_TYPES.update: return { @@ -160,13 +161,11 @@ export default (props: ViewerProps) => { React.useEffect(() => { if (visible) { - setTimeout(() => { - if (init.current) { - dispatch(createAction(ACTION_TYPES.setVisible, { - visible: true, - })); - } - }, 10); + if (init.current) { + dispatch(createAction(ACTION_TYPES.setVisible, { + visible: true, + })); + } } }, [visible]); @@ -296,15 +295,6 @@ export default (props: ViewerProps) => { } }, [state.startLoading, state.activeIndex]); - React.useEffect(() => { - if (state.activeIndex === null || !state.visible) { - return; - } - dispatch(createAction(ACTION_TYPES.update, { - startLoading: true, - })); - }, [state.activeIndex, state.visible]); - function getImgWidthHeight(imgWidth, imgHeight) { let width = 0; let height = 0;