Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

276
Views
Llamada de gancho no válida. Los ganchos solo se pueden llamar dentro del cuerpo de un componente de función (react-native)

Error: llamada de gancho no válida. Los ganchos solo se pueden llamar dentro del cuerpo de un componente de función. Esto podría suceder por una de las siguientes razones:

  1. Es posible que tenga versiones que no coincidan de React y el renderizador (como React DOM)
  2. Podrías estar rompiendo las Reglas de los Hooks
  3. Es posible que tenga más de una copia de React en la misma aplicación

Estoy tratando de implementar el permiso de ubicación en reaccionar nativo (estoy usando expo CLI)

esta es la función que ya creé:

 function OfferScreen({ navigation}: {navigation:any}) { //STATE VARIABLES FOR FETCHING DATA const [loading, setLoading] = useState(true); const [data, setData] = useState([]); const value = new Animated.Value(1); //FETCHING DATA React.useEffect(() => { fetch("https://fidness.net/WSExchange/getListActiveProspectus") .then((response) => response.json()) .then((json) => { setData(json); setLoading(false); }) .catch((error) => { alert( "Erreur avec le chargement des offres, veuillez réssayer ultérieurement!" ); setLoading(false); }); //GEOLOCATION TEST //STATE FOR GEOLOCATION const [location, setLocation] = useState < any | null > (null); const [hasPermission, setHasPermission] = useState < any | null > (null); useEffect(() => { (async () => { const {status} = await Location.requestForegroundPermissionsAsync(); setHasPermission(status === "granted"); let location = await Location.getCurrentPositionAsync({}); })(); }, []); } export default OfferScreen;

y esta es la función de destino en mi barra de pestañas

 <Tab.Screen //TABSCREEN OFFER options={ {headerShown: false} } name={"Offres"} component={Offers}/>

y por cierto cuando elimino el código de permiso de ubicación funciona bien.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

No puede tener useState() dentro de un React.useEffect() . Mueva estas declaraciones a la parte superior y fuera de useEffect

 function OfferScreen({ navigation }: { navigation: any }) { //STATE VARIABLES FOR FETCHING DATA const [loading, setLoading] = useState(true); const [data, setData] = useState([]); const value = new Animated.Value(1); //GEOLOCATION TEST //STATE FOR GEOLOCATION const [location, setLocation] = (useState < any) | (null > null); const [hasPermission, setHasPermission] = (useState < any) | (null > null); React.useEffect(() => { if (!loading && data) { (async () => { const { status } = await Location.requestForegroundPermissionsAsync(); setHasPermission(status === "granted"); let location = await Location.getCurrentPositionAsync({}); })(); } }, [data, loading]); //FETCHING DATA React.useEffect(() => { fetch("https://fidness.net/WSExchange/getListActiveProspectus") .then((response) => response.json()) .then((json) => { setData(json); setLoading(false); }) .catch((error) => { alert( "Erreur avec le chargement des offres, veuillez réssayer ultérieurement!" ); setLoading(false); }); }, []); } export default OfferScreen;
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!