This is a weather application built using React with Vite, styled using Tailwind CSS, and fetching weather data from the OpenWeather API.
The app utilizes the navigator.geolocation
object to retrieve the user's current location, and a custom hook useGeolocation
was created to handle and provide the user's coordinates. The app also leverages Axios for API requests, Tanstack Query (formerly React Query) for data fetching and caching, JSX for structuring components, and React Hooks for state and effect management.
navigator.geolocation
to detect the user's current position.useGeolocation
hook for managing geolocation data.useFetchWeather
hook for managing weather data.You can view a live demo of the app here.
You can watch a YouTube video on how to build Weather App
useGeolocation
, useFetchWeather
, useState
, useEffect
)To get a local copy up and running, follow these steps:
Make sure you have the following installed:
Clone the repository:
git clone https://github.com/DzmitryUr/weather-app-react.git
cd weather-app-react
Install dependencies:
npm install
Create a .env.local file at the root of the project and add your OpenWeather API Key and Google Analytics ID(optional):
VITE_API_KEY=your_openweather_api_key
You can get your API key by signing up at OpenWeather.
You can use file .env.example
as an example
Start the development server:
npm run dev
Open the app in your browser:
http://localhost:5173
useGeolocation
hook to retrieve your coordinates and display the weather for your current location.If you'd like to contribute, feel free to create a pull request or open an issue to discuss the changes.
This project is licensed under the MIT License.