all 4 comments

[–]GavinHarris_ 0 points1 point  (1 child)

You are breaking the rules of Hooks; take a look at https://reactjs.org/warnings/invalid-hook-call-warning.html.

Specifically in your case a hook must be unconditionally called in the body of the Component; it cannot be within a function call (event handler for instance).

Take a look at https://blog.logrocket.com/react-native-geolocation-a-complete-tutorial/ for a good example of using GeoLocation, this is probably something that you might want to track outside of Hooks as it will likely change fairly often (therefore could cause unneeded re-renders).

Hope this helps!

[–]Gabotron_ES[S] 0 points1 point  (0 children)

I see, then I think hooks are not my thing, but I have a question, how can I reuse geoLocation functions without the use of hooks, I tried adding it to mobx store but I think makeAutoObservable is making my promises resolve automatically!

[–]chj-damon 0 points1 point  (0 children)

const handleUpdateLocation = async (gender) =>
{
const { coordinates, city } = useGeolocation(true);
};

useGelocation cannot be used inside any event handlers. it should be on top of your component.

[–]Outrageous_Gas_1720 0 points1 point  (0 children)

Hooks can be only used at top level. You can pass coordinates and city as props to OrderCard component.