[question] Example of new context API in use
See original GitHub issueCan 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:
class MyComponent extends React.Component<Props> {
static contextTypes = {
map: PropTypes.object.isRequired
};
}
To then be able to access the map object to update the cursor type when hovering elements, e.g.
circleOnMouseEnter={event => {
map.getCanvas().style.cursor = "pointer";
onEnterFeature(event.features[0]);
}}
Thanks!
Issue Analytics
- State:
- Created 5 years ago
- Comments:13 (9 by maintainers)
Top Results From Across the Web
React Context API: A deep dive with examples - LogRocket Blog
In this tutorial, we'll explore how we can use React Context to avoid prop drilling.
Read more >20 React Context API Interview Questions and Answers - CLIMB
Here are 20 commonly asked React Context API interview questions and answers to ... First, the new API is more flexible and easier...
Read more >How to Work with the React Context API - Toptal
Once that's done, we can import the context and use it to create our provider, which we're calling MyProvider. In it, we initialize...
Read more >A Guide to React Context and useContext() Hook
The React context provides data to components no matter how deep they are in the components tree. The context is used to manage...
Read more >React Context API: What is it and How it works?
How to use Context API? · Create a component that will wrap the provider named Provider e.g. UserProvider. Example using React Hooks: ·...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
event.target
is the map@nathanredblur If you want to use context, but don’t want to render anything there, you can just
return null
in that function. You could also use hooks to access the map in a component:const map = React.useContext(MapContext)