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

334
Views
Cómo hacer que axios funcione con expo (reaccionar nativo)

Estoy tratando de llamar al clima local desde openweathermap en mi aplicación nativa de reacción. He probado la URL tanto en el navegador como en el código en un proyecto de reacción simple y funciona. Sin embargo, en reaccionar nativo no lo hace.

Aquí está mi código:

 function Overview() { const appState = useRef(AppState.currentState); const [count, setCount] = useState(0); const [active, setActive] = useState(false); const [latitude, setLatitude] = useState(0); const [longitude, setLongitude] = useState(0); const [temperature, setTemperature] = useState(''); const API_KEY = '{...apikey...}'; const getLocationAsync = async () => { let {status} = await Location.requestForegroundPermissionsAsync(); if (status !== 'granted') { console.log('Location Permission Error') } const loc = await Location.getCurrentPositionAsync({}); setLatitude(loc.coords.latitude); setLongitude(loc.coords.longitude); } const getTemperature = useCallback(async () => { const url = `https://api.openweathermap.org/data/2.5/weather?lat=${latitude.toFixed(2)}&lon=${longitude.toFixed(2)}&appid=${API_KEY}`; console.log("my provided url is set to:", url); const response = await axios.get(url); if (response.data) { setTemperature(response.data.main.temp); } }, [latitude, longitude]) useEffect(() => { appState.current.match('active') ? setActive(true) : setActive(false) active && setInterval(() => setCount((oldCount) => oldCount + 1), 60000); getLocationAsync(); return () => { clearInterval(); }; }, [active]); useEffect(() => { getTemperature() .catch(console.error); }, [getTemperature]) return ( <View style={{margin: 32}}> <View style={{marginBottom: 32}}> <Text style={{fontSize: 36, fontFamily: 'Roboto_400Regular'}}>Great!</Text> <Text style={{fontSize: 16, color: '#878787', fontFamily: 'Roboto_400Regular'}}>Average mood 23%</Text> </View> <View style={{flexDirection: 'row', justifyContent: 'space-between'}}> <OverviewContainer title="Weather" value={temperature ? temperature : "no data"}/> <OverviewContainer title="Time on app" value={secondsToHms(count)}/> </View> </View> ); }

Originalmente pensé que podría ser un problema con mi código, pero lo corregí para asegurarme de que funcionaba. He leído en otras preguntas que en expo necesitas agregar tu ip y puerto a la url. Sin embargo, al probar esto, todavía no pude hacerlo funcionar. ¡Cualquier ayuda sería genial!

about 4 years ago · Juan Pablo Isaza
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!