0
Hello, When trying to call a function that has a hook call the following error appears:
And here’s the excerpt from the code:
currentLocation.js
import React, {useState} from 'react'
export function locationUser(){
...
const [coordinates, setCoordinates] = useState({
latitude:0,
longitude: 0,
error: null
});
...
return console.log(coordinates);
}
index js.
import React from 'react';
import { View, Button, Text } from 'react-native';
import { locationUser } from '../../services/currentLocation'
export default function Home(){
return(
<View>
...
<Button onPress={() => locationUser()}>
<Text>INICIAR</Text>
</Button>
...
</View>
);
}
if you try to execute locationUser without is inside the fuction Arrow works, however, is not right, because the function will run infinitely, since a normal function runs as soon as the code is started.
Can someone help me? =)
More in my case I’m using Function Component and not Class Component, in which part do you think I’m mixing?
– Luh