Skip to content

Commit

Permalink
type(Map): Rename type Context -> ContextState.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Apr 15, 2022
1 parent a730fff commit cafd67d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
6 changes: 4 additions & 2 deletions packages/map/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ Map 组件是其他组件的基础,Map 组件会给所有的子组件注入两
<!--rehype-->
```jsx
import { Map, useMap, APILoader } from '@uiw/react-baidu-map';
import { Map, useMap, APILoader, Provider, useMapContext } from '@uiw/react-baidu-map';
// 或者单独安装使用
import Map, { useMap, APILoader } from '@uiw/react-baidu-map-map';
import Map, { useMap, APILoader, Provider, useMapContext } from '@uiw/react-baidu-map-map';
```

🚧 注意:需要使用到 `<Provider>`,新的封装 `Marker` 组建使用了 `Context` 来避免 `map` 对象传来传去。

### 基本用法

Map 的父组件必须具有宽度和高度;
Expand Down
4 changes: 2 additions & 2 deletions packages/map/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ export const reducer = (state: InitialState, action: InitialState) => {
};
};

export interface Context {
export interface ContextState {
state: Partial<InitialState>;
dispatch: React.Dispatch<InitialState>;
}

export const Context = React.createContext<Context>({
export const Context = React.createContext<ContextState>({
state: initialState,
dispatch: () => null,
});
Expand Down
1 change: 1 addition & 0 deletions packages/map/src/useMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export function useMap(props: UseMap = {}) {
return () => {
dispatch({ map: undefined, container: undefined, BMap: undefined });
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [map, container]);

const [center, setCenter] = useState(props.center || '上海');
Expand Down

0 comments on commit cafd67d

Please sign in to comment.