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

egghead
egghead
~ 37 seconds 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