1. 27
    Accesse Leaflet Map Instance Inside a React useEffect Hook
    16s

Accesse Leaflet Map Instance Inside a React useEffect Hook

Colby Fayock
InstructorColby Fayock
Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 3 years ago

Once we have a ref set up, we gain the ability to access that ref within React's useEffect hook.

With this, we'll access the current value at the time the useEffect hook is ran.

You can test this out by using the console.log feature and verifying that when logging inside of useEffect, you'll see that your ref has a property of current with a value.

Click here for exercise instructions

Instructor: [0:00] In order to access our map from our ref we're going to use the useEffect Hook. We can start by creating a new instance of this hook where we pass in an empty function.

[0:06] For the dependency array, we're going to set our mapRef. In order to test this out, we can console.log() out our mapRef, and we can actually specify the current property. If we reload the page, we can see that we now our console logging out our map.

egghead
egghead
~ 38 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today