“React Weather App” Réponses codées

React Weather App

import './App.css';
import React, { useEffect, useState } from "react";
import Weather from './components/weather';
export default function App() {
  
  const [lat, setLat] = useState([]);
  const [long, setLong] = useState([]);
  const [data, setData] = useState([]);

  useEffect(() => {
    const fetchData = async () => {
      navigator.geolocation.getCurrentPosition(function(position) {
        setLat(position.coords.latitude);
        setLong(position.coords.longitude);
      });

      await fetch(`${process.env.REACT_APP_API_URL}/weather/?lat=${lat}&lon=${long}&units=metric&APPID=${process.env.REACT_APP_API_KEY}`)
      .then(res => res.json())
      .then(result => {
        setData(result)
        console.log(result);
      });
    }
    fetchData();
  }, [lat,long])
  
  return (
    <div className="App">
      {(typeof data.main != 'undefined') ? (
        <Weather weatherData={data}/>
      ): (
        <div></div>
      )}
      
    </div>
  );
}
Said HR

React Weather App

npm install semantic-ui-react semantic-ui-css
Wide-eyed Weevil

React_weather_app

024676ac355409c93be1280b0e619122
Nervous Nightingale

Réponses similaires à “React Weather App”

Questions similaires à “React Weather App”

Plus de réponses similaires à “React Weather App” dans JavaScript

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code