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 4 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.