Skip to content

Commit

Permalink
fix: handle pr
Browse files Browse the repository at this point in the history
  • Loading branch information
Yilun-Sun committed Nov 7, 2022
1 parent f32b504 commit c838e94
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 31 deletions.
11 changes: 2 additions & 9 deletions src/guide/Guide.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import useConfig from '../hooks/useConfig';
import Popup from '../popup';
import { GuideCrossProps, StepPopupPlacement, TdGuideProps } from './type';
import { addClass, removeClass, isFixed, getWindowScroll } from '../_util/dom';
import { scrollToParentVisibleArea, getRelativePosition, getTargetElm, scrollToElm } from './utils';
import { scrollToParentVisibleArea, getRelativePosition, getTargetElm, scrollToElm, useMount } from './utils';
import setStyle from '../_common/js/utils/set-style';
import useControlled from '../hooks/useControlled';
import { guideDefaultProps } from './defaultProps';
Expand Down Expand Up @@ -183,14 +183,7 @@ const Guide = (props: GuideProps) => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [innerCurrent]);

useEffect(() => {
initGuide();

return () => {
destroyGuide();
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
useMount(initGuide, destroyGuide);

const renderOverlayLayer = () =>
createPortal(
Expand Down
4 changes: 2 additions & 2 deletions src/guide/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { scrollToParentVisibleArea } from './getScrollParent';
import getRelativePosition from './getRelativePosition';
import getTargetElm from './getTargetElm';
import scrollToElm from './scrollToElm';
import useWatch from './useWatch';
import useMount from './useMount';

export { scrollToParentVisibleArea, getRelativePosition, getTargetElm, scrollToElm, useWatch };
export { scrollToParentVisibleArea, getRelativePosition, getTargetElm, scrollToElm, useMount };
18 changes: 18 additions & 0 deletions src/guide/utils/useMount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { useEffect, useRef } from 'react';

export default function useMount(mount: () => void, unmount: () => void) {
const isMounted = useRef(true);

return useEffect(() => {
if (isMounted.current) {
isMounted.current = false;

return;
}

mount();

return unmount;
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}
20 changes: 0 additions & 20 deletions src/guide/utils/useWatch.ts

This file was deleted.

0 comments on commit c838e94

Please sign in to comment.