From 5a398477ee4cf3369508ecfb8315919335c7e33d Mon Sep 17 00:00:00 2001 From: infeng Date: Mon, 16 Sep 2019 16:42:54 +0800 Subject: [PATCH] fix: activeIndex error --- src/ViewerCore.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/ViewerCore.tsx b/src/ViewerCore.tsx index 4cf0f7d..440e044 100644 --- a/src/ViewerCore.tsx +++ b/src/ViewerCore.tsx @@ -197,10 +197,12 @@ export default (props: ViewerProps) => { }, [state.visible]); React.useEffect(() => { - dispatch(createAction(ACTION_TYPES.setActiveIndex, { - index: activeIndex, - })); - }, [activeIndex]); + if (visible) { + dispatch(createAction(ACTION_TYPES.setActiveIndex, { + index: activeIndex, + })); + } + }, [activeIndex, visible]); function loadImg(currentActiveIndex, isReset = false) { dispatch(createAction(ACTION_TYPES.update, {