-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hook-example: Explain how useMap in code comments
- Show how useMap works on first render, second render - Hint at useMap not working outside Add console statements and code comments to reference how useMap works in the different situations. The code comment help understand that useMap returns undefined first; and what the shape of the returned object looks like. The controls2 component shows how the "current" works when useMap is used inside a Map component. All console logs are formatted as code comments so they are easy to reproduce but don't actually log.
- Loading branch information
Showing
4 changed files
with
84 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import {useMap} from 'react-map-gl'; | ||
|
||
export default function Controls2() { | ||
/** | ||
* ## This is how `useMap` works: | ||
* This component does nothing. It's purpose is to demo `useMap`. | ||
* When a component is a child of `<Map>`, `useMap` has a `current` field that references the containing map. | ||
* See https://visgl.github.io/react-map-gl/docs/api-reference/use-map | ||
* See https://visgl.github.io/react-map-gl/docs/api-reference/types#mapref | ||
* ``` | ||
* const demo = useMap(); | ||
* console.log('Controls2', {demo}); | ||
* ``` | ||
* ### First render: | ||
* ``` | ||
* { | ||
* "demo": { | ||
* "current": {...}, | ||
* "mymap": {...} | ||
* } | ||
* } | ||
* ``` | ||
*/ | ||
|
||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters