Skip to content

Commit

Permalink
fix(Map): Fix center props errors. #134
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed May 19, 2021
1 parent 09c732d commit 45c642d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
6 changes: 2 additions & 4 deletions src/Map/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// <reference types="../types" />

import React, { useRef, useEffect, useImperativeHandle, Fragment } from 'react';
import React, { useRef, useEffect, useImperativeHandle, Fragment, useMemo } from 'react';
import useMap from './useMap';

export interface Control {
Expand Down Expand Up @@ -117,9 +117,7 @@ export default React.forwardRef<MapProps & { map?: BMap.Map }, MapProps & MapChi
...props,
});
useEffect(() => setContainer(elmRef.current as string | HTMLDivElement | undefined), [elmRef.current]);
useEffect(() => {
props.center && setCenter(props.center);
}, [props.center]);
useMemo(() => props.center && setCenter(props.center!), [props.center]);
useEffect(() => setAutoLocalCity(props.autoLocalCity!), [props.autoLocalCity]);
useImperativeHandle(ref, () => ({ ...props, map, BMap, container: elmRef }), [map]);
const childs = React.Children.toArray(children);
Expand Down
5 changes: 1 addition & 4 deletions src/Map/useMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,8 @@ export default function useMap(props: UseMap = {}) {
if (center && (center as BMap.Point).lng && (center as BMap.Point).lat) {
cent = new BMap.Point((center as BMap.Point).lng, (center as BMap.Point).lat);
map.centerAndZoom(cent!, zoom!);
map.setCenter(cent);
} else if (typeof center === 'string') {
map.centerAndZoom(center, zoom!);
map.setCenter(center);
}
map.centerAndZoom(center, zoom!);
}
}, [center, map]);

Expand Down

0 comments on commit 45c642d

Please sign in to comment.