New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[question] Example of new context API in use #649
Comments
|
I'm doing something similar in 3.x but trying to upgrade to 4.x and ran into the same issue. The difference is I'm trying to access the map from context and don't have an event to pull the map from. Is there any way to access the map context? |
btw I found a solution here: #691 (comment) Sounds like when #654 is solved it'll be a little easier to use |
If anyone ever lands here looking for help with context API, the docs now include a section on it: |
Is not possible to use the example with typescript:
|
@nathanredblur indeed, as the types say, the render prop function needs to return a ReactNode, not be a void function. |
@nathanredblur If you want to use context, but don't want to render anything there, you can just |
@redbmk Awesome Idea!, I will try that. That shoul be in the documentation. const Map = () => {
const map = React.useContext(MapContext)
React.useEffect(() => {
console.log(map)
}, [map])
return(<Mapbox />)
} |
@nathanredblur The component that's reading from the It should look more like this:
|
Same issue here. Any solution, please? |
@tarim did the solution above not work for you? What issue are you having exactly? You should be able to Then as long as your component is a child of a |
Example doesn't work in typescript, get the following:
|
@zbyte64 Any chance you could post a sample of what you're trying in something like codesandbox? Here's something I threw together based on the previous discussion, which seems to be working. You'll need to add your access token to make it work completely, but I'm not seeing that typescript error you are. |
Can we get a quick example of the new context API for those upgrading from react-mapbox-gl 3.9.x to 4.0.0?
In my case I'm doing the following:
To then be able to access the map object to update the cursor type when hovering elements, e.g.
Thanks!
The text was updated successfully, but these errors were encountered: