Now that we have finished up with our map app, let's do a little cleaning up! Here we are going to go through our Location Event Handler and clean it up for when the page unmounts.
Colby Fayock: [0:00] Anytime we create an event listener, we want to try to be thoughtful and clean those up on the component unmounts. This way, we don't have any stray resources being hung up.
[0:07] To do this, our useEffect hook lets us return a statement to run after unmounts. We're going to tell this to return a new function, or we're going to tell our map to turn off our location found event along with that function.
[0:18] When we go to the browser and click Find My Location, we're not going to see anything different, but now we know we're going to be cleaning up those resources whenever it unmounts.
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
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!