Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

react weather app

npm install semantic-ui-react semantic-ui-css
Comment

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>
  );
}
Comment

React_Weather_App

024676ac355409c93be1280b0e619122
Comment

PREVIOUS NEXT
Code Example
Javascript :: sum an array of objects 
Javascript :: js role giver 
Javascript :: react map list render dictionary 
Javascript :: to htmlhow can i add the list in javascript 
Javascript :: javaScript add() Method 
Javascript :: where to create service angularor nodejs 
Javascript :: callbacks in jquery 
Javascript :: && operator in react 
Javascript :: js date toisostring with timezone 
Javascript :: vue js tutorial csv import 
Javascript :: how to check if input is valid javascript 
Javascript :: js remove several elements from array 
Javascript :: even numbers in an array 
Javascript :: star print in javascript 
Javascript :: set route on button in angular 
Javascript :: component navigation without changin the url react router 
Javascript :: difference between w component did update and did mount 
Javascript :: is js dead 
Javascript :: how to loop elements in javascript for of loop 
Javascript :: react js props lara css uygulama 
Python :: abc list python 
Python :: python shebang 
Python :: how to install matplotlib in python 
Python :: python currnent time now 
Python :: extract year from datetime pandas 
Python :: play video in google colab 
Python :: python kivy Kivy files require #:kivy ! 
Python :: how to change pygame window icon 
Python :: matplotlib.pyplot imshow size 
Python :: split validation set 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =