Skip to content

Commit

Permalink
type: Fix type errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Sep 9, 2021
1 parent d567d19 commit 01b09a0
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 19 deletions.
1 change: 1 addition & 0 deletions src/Circle/useCircle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default function useCircle(props = {} as UseCircle) {
map.addOverlay(instance);
setCircle(instance);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [map, circle]);

useVisiable(circle!, props);
Expand Down
2 changes: 1 addition & 1 deletion src/GeolocationControl/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
NavigationControl 平移缩放控件
GeolocationControl 定位控件
===

负责进行地图定位的控件,使用html5浏览器定位功能。你也可以使用 `Map` 组件 `widget` 属性来设置控件更方便。
Expand Down
2 changes: 1 addition & 1 deletion src/GeolocationControl/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export interface GeolocationControlProps extends OverlayProps, BMap.GeolocationC

export default React.forwardRef<GeolocationControlProps, GeolocationControlProps>((props, ref) => {
const { geolocationControl } = useGeolocationControl(props);
useImperativeHandle(ref, () => ({ ...props, geolocationControl }), [geolocationControl]);
useImperativeHandle(ref, () => ({ ...props, geolocationControl }), [geolocationControl, props]);
return null;
});
18 changes: 5 additions & 13 deletions src/common/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,10 @@ import React, { useEffect, useState, useRef } from 'react';
export function useEnableProperties<T = {}, F = {}>(instance: T, props = {} as F, propsName: string[] = []) {
propsName.forEach((name) => {
const eName = `enable${name}` as keyof F;
const [state, setState] = useState(props[eName]);
useEffect(() => {
const funName = (props[eName] ? `enable${name}` : `disable${name}`) as keyof T;
if (instance && props[eName] !== undefined) {
instance[funName] && (instance[funName] as any)();
if (props[eName] !== state) {
setState(props[eName]);
}
}
}, [instance, props[eName]]);
const funName = (props[eName] ? `enable${name}` : `disable${name}`) as keyof T;
if (instance && props[eName] !== undefined) {
instance[funName] && (instance[funName] as any)();
}
});
}

Expand All @@ -41,9 +35,7 @@ export function useVisiable<T extends BMap.Overlay, F extends { visiable?: boole
const [state, setState] = useState(visiable);
useEffect(() => {
if (instance && visiable !== undefined) {
console.log('visiable', visiable);
if (visiable) {
console.log('visiable', instance);
instance.show && instance.show();
} else {
instance.hide && instance.hide();
Expand All @@ -52,7 +44,7 @@ export function useVisiable<T extends BMap.Overlay, F extends { visiable?: boole
setState(visiable);
}
}
}, [instance, visiable]);
}, [instance, state, visiable]);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/common/useCreatePortal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface UseCreatePortal {
children?: React.ReactNode;
}

export default (props = {} as UseCreatePortal) => {
export default function useCreatePortal(props = {} as UseCreatePortal) {
const [div, setDiv] = useState<HTMLDivElement>(document.createElement('div'));
const [portal, setPortal] = useState<React.ReactPortal>();
const [count, setCount] = useState(0);
Expand All @@ -20,7 +20,7 @@ export default (props = {} as UseCreatePortal) => {
setCount(count + 1);
setPortal(portalInstance);
}
}, [portal]);
}, [children, count, div, portal]);

const prevCount = usePrevious(count);
useMemo(() => {
Expand All @@ -29,7 +29,7 @@ export default (props = {} as UseCreatePortal) => {
setCount(count + 1);
setPortal(portalInstance);
}
}, [children, div, portal]);
}, [children, count, div, prevCount]);

return {
div,
Expand All @@ -39,4 +39,4 @@ export default (props = {} as UseCreatePortal) => {
children,
setChildren,
};
};
}

0 comments on commit 01b09a0

Please sign in to comment.