1. 21
    Fix react-leaflet Peer Dependencies Conflicts with useEffect Hook
    32s

Fix react-leaflet Peer Dependencies Conflicts with 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 added the Marker, the first thing we noticed is it didn't work! 😱

We can fix this though by overriding the library's default images with images imported straight from the library itself. It sounds confusing, but we'll walk through this together and see it not working on the page.

Click here for exercise instructions

Colby Fayock: [0:00] It turns out the tools like create-react-app work is they're not able to produce the right location for each of our images. To fix that, we're going to override some of the Leaflet defaults to fix our marker images. To do that, we're going to use a useEffect hook.

[0:11] We'll first import that where we'll set up an instance of it with a new function and an empty dependency array. Inside that, we'll paste the code snippet we found in the GitHub issue. First, we're going to delete this default, and we're going to set up some new ones with the imports directly from Leaflet.

[0:24] Finally, since we're using Leaflet here, we have to import it. At the top we're going to import L from 'leaflet'. Now, if we open back up our map, we can see our marker.