Skip to content
Advertisement

React Hooks: useState updater function: Why does this hook remove the object upon drag?

I have a marker on a map which takes this function upon dragging:

JavaScript

That function fires another function updateUserMarker, which is coming from a component via context:

It consumes the index, a new object which contains updated lat and long from the event, & appends an id which will also be from the event.

In the context component, I have this function:

JavaScript

It works fine with the first objects—lat and lang, but upon adding the second object after the dragging commences it disappears!

Probably should have tried to come here hours ago, but wanted to give it my best effort!

Thank you in advance!

Advertisement

Answer

I am not sure why you used [0] for updatedMarker. I assume that you want to update the marker whose id is matched with markerIndex.

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement