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 :: Using toLocaleString() to Print JavaScript Number Format with Commas 
Javascript :: getData(x, y, callback) and showData() callback function 
Javascript :: Example of Logical OR assignment operator in es12 
Javascript :: Custom usePagination hook 
Javascript :: Allowed Blocks in Nested Blocks Component Wordpress 
Javascript :: Multiline string in ES6 
Javascript :: blur area behind an element in react native 
Javascript :: hover over class apply to subclass 
Javascript :: format file using jq input curl 
Javascript :: javascript responsive carousel 
Javascript :: generic product filter javascript 
Javascript :: Getting Specific Element Properties 
Javascript :: javascript dropdown options auto-updating 
Javascript :: javascrpt 
Javascript :: he "slide" event cannot be bound because Hammer.JS is not loaded and no custom loader has been specified 
Javascript :: for (var i = 0; i < 3; i++) { setTimeout(function() { console.log(i); }, 1000 + i); } 
Javascript :: get seo friendly url values in javascript 
Javascript :: javascript return opposite boolean 
Javascript :: how to add carsoul to react project 
Javascript :: substraction js 
Javascript :: make form submit on new window using jquery 
Javascript :: update mongoose 
Javascript :: get a list of field name from object javascript 
Javascript :: get members of a group graph pnp js 
Javascript :: gsheet get cell background color 
Javascript :: form react js 
Javascript :: pass image as props vue vuetify 
Javascript :: unexpected token useeffect react native 
Javascript :: js to jquery ONLINE converter 
Javascript :: js array piush 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =