Skip to content

Commit 84679cb

Browse files
committed
docs: add hooks & etc content
1 parent 85d11e8 commit 84679cb

7 files changed

Lines changed: 133 additions & 10 deletions

File tree

docs/astro.config.mjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ export default defineConfig({
8989
label: 'Hooks',
9090
items: [
9191
{
92-
label: 'useMapContext 🛠',
92+
label: 'useMapContext',
9393
link: '/docs/api/use-map-context',
9494
},
9595
{
96-
label: 'useImportLibrary 🛠',
96+
label: 'useImportLibrary',
9797
link: '/docs/api/use-import-library',
9898
},
9999
{
100-
label: 'useApiLoadingStatus 🛠',
100+
label: 'useApiLoadingStatus',
101101
link: '/docs/api/use-api-loading-status',
102102
},
103103
],
@@ -106,11 +106,11 @@ export default defineConfig({
106106
label: 'etc',
107107
items: [
108108
{
109-
label: 'LoadingStatus 🛠',
109+
label: 'LoadingStatus',
110110
link: '/docs/api/loading-status',
111111
},
112112
{
113-
label: 'appendLibImportScript 🛠',
113+
label: 'appendLibImportScript',
114114
link: '/docs/api/append-lib-import-script',
115115
},
116116
],
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { useEffect } from "react";
2+
import { GoogleMap, Marker, useMapContext } from "react-google-map-wrapper";
3+
4+
import { Container } from "../../Container";
5+
6+
function MapContent() {
7+
const map = useMapContext();
8+
9+
console.log(map);
10+
11+
useEffect(() => {
12+
setTimeout(() => {
13+
map.fitBounds({
14+
south: 37.5211158,
15+
north: 37.5011158,
16+
west: 127.098167,
17+
east: 127.098167,
18+
})
19+
}, 3000);
20+
}, []);
21+
22+
return (
23+
<Marker lat={37.5111158} lng={127.098167} title='Lotte World' />
24+
)
25+
}
26+
27+
export function UseMapContextEx() {
28+
return (
29+
<Container>
30+
<GoogleMap
31+
className='h-[400px]'
32+
zoom={16}
33+
center={{ lat: 37.5111158, lng: 127.098167 }}
34+
>
35+
<MapContent />
36+
</GoogleMap>
37+
</Container>
38+
)
39+
}

docs/src/content/docs/docs/api/append-lib-import-script.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ title: appendLibImportScript
33
description: description
44
---
55

6-
🛠🛠🛠 This documentation is currently in progress. 🛠🛠🛠
6+
`appendLibImportScript` function add the inline bootstrap loader script to the header that Load the Maps JavaScript API.
7+
8+
<a href='./google-map-api-loader'>GoogleMapApiLoader</a> call this function, so you don't need to call it yourself. but if you want to preload Google Maps script, you can call it manually in the root file.

docs/src/content/docs/docs/api/loading-status.mdx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,12 @@ title: LoadingStatus
33
description: description
44
---
55

6-
🛠🛠🛠 This documentation is currently in progress. 🛠🛠🛠
6+
`LoadingStatus` is enum for google map loading status.
7+
8+
```tsx
9+
export enum LoadingStatus {
10+
LOADING = 'LOADING', // loading
11+
FAILURE = 'FAILURE', // loading failed
12+
SUCCESS = 'SUCCESS', // loading finished
13+
}
14+
```

docs/src/content/docs/docs/api/use-api-loading-status.mdx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,27 @@ title: useApiLoadingStatus
33
description: description
44
---
55

6-
🛠🛠🛠 This documentation is currently in progress. 🛠🛠🛠
6+
`useApiLoadingStatus` hooks is used for get current <a href='./loading-status'>LoadingStatus</a>.
7+
8+
In most cases, you won't need to use it.
9+
10+
### Basic Example
11+
12+
```tsx
13+
function App() {
14+
const loadingStatus = useApiLoadingStatus();
15+
16+
return (
17+
<GoogleMapApiLoader
18+
apiKey='YOUR_API_KEY'
19+
>
20+
{
21+
loadingStatus === LoadingStatus.SUCCESS && (
22+
// now you can use Google Map API.
23+
<MyMap />
24+
)
25+
}
26+
</GoogleMapApiLoader>
27+
);
28+
}
29+
```

docs/src/content/docs/docs/api/use-import-library.mdx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,11 @@ title: useImportLibrary
33
description: description
44
---
55

6-
🛠🛠🛠 This documentation is currently in progress. 🛠🛠🛠
6+
`useImportLibrary` hooks is a wrapper of <a href='https://developers.google.com/maps/documentation/javascript/reference/top-level#google.maps.importLibrary' target='_blank' rel='noreferrer'>importLibrary</a>
7+
8+
### function type
9+
10+
```ts
11+
<Name extends LibraryName, Lib = LibraryMap[Name]>(libName: Name) => Lib | null;
12+
```
13+

docs/src/content/docs/docs/api/use-map-context.mdx

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,48 @@ title: useMapContext
33
description: description
44
---
55

6-
🛠🛠🛠 This documentation is currently in progress. 🛠🛠🛠
6+
import { UseMapContextEx } from '../../../../components/api/useMapContext';
7+
8+
`useMapContext` hooks read <a href='https://developers.google.com/maps/documentation/javascript/reference/map#Map' target='_blank' rel='noreferrer'>Map</a> instance of the <a href='./google-map'>GoogleMap</a> component.
9+
10+
### Basic Example
11+
12+
```tsx
13+
function MapContent() {
14+
const map = useMapContext();
15+
16+
console.log(map);
17+
18+
useEffect(() => {
19+
setTimeout(() => { // refresh and watch the example below!
20+
map.fitBounds({
21+
south: 37.5211158,
22+
north: 37.5011158,
23+
west: 127.098167,
24+
east: 127.098167,
25+
})
26+
}, 3000);
27+
}, []);
28+
29+
return (
30+
<Marker lat={37.5111158} lng={127.098167} title='Lotte World' />
31+
);
32+
}
33+
34+
function MyMap() {
35+
return (
36+
<GoogleMap
37+
className='h-[400px]'
38+
center={{ lat: 37.5111158, lng: 127.098167 }}
39+
>
40+
<MapContent />
41+
</GoogleMap>
42+
);
43+
}
44+
```
45+
46+
<UseMapContextEx client:only='react' />
47+
48+
### Alternative
49+
50+
You can use <a href='./google-map'>GoogleMap</a> event callbacks(`onLoad`, etc.) or `ref` props to get a <a href='https://developers.google.com/maps/documentation/javascript/reference/map#Map' target='_blank' rel='noreferrer'>Map</a> instance.

0 commit comments

Comments
 (0)