Map.off is not working

I am trying use the map.on and map.off events to add and remove markers. The map.on(“click”, () => {} ), however, map.off(“click”, () => {} ) doesn’t remove the click event.

Did you use named listener function or just used the same code in {} ?

yea I did. map.on(“click”, () => {} ) and map.off(“click”, () => {} )

try to put the code into a named function and then use it like that:

map.on("click", myListenerFn)

and then

map.off("click", myListenerFn)