I've seen a lot of code like this:
navigator.geolocation.getCurrentPosition(
({coords}) => {
const {latitude, longitude} = coords
this.setState({
position: {
latitude,
longitude,
},
region: {
latitude,
longitude,
latitudeDelta: 0.005,
longitudeDelta: 0.001,
}
})
},
(error) => alert('Error: Are location services on?'),
{enableHighAccuracy: true}
);
My question is why and when we use object destructuring in parameter.
Why coords using object destructuring while error not using it?
({coords})destructures,(error)does not ... use{}to destructure the incoming argument, don't use{}to get the whole argument - perhaps I've misunderstood your question, you seem to know what{}does, you want to know why you'd do it? because you're only interested in thecoordsproperty of the argument and nothing else in the object that is passed in the argument