In this article, we are going to make a weather app in react. In this project, we will use openweather API which provides us free API to get weather details. Here we will add an input field where user will add any city name and as soon city name gets entered an API call will occur and details will be fetched to the screen. This App will be completely depends on API.
So basically this is going to be a beginner-friendly project, so let’s make this project step-by-step.
Pre-requisites to Make Calculator in React
- Basic knowledge of ReactJS.
- Basic knowledge of React hooks.
- Good knowledge of React Components.
Adding API And Key
Now before jumping into the code, let’s get the API and Key which we will use for this project. For that, we have to move to openweather.org site and just login to get API key. After that, in our App.js component, we have added a constant in which we have assigned our API key to the key constant, and we have provided a URL in our base constant. Also, we have two cool pictures we will differ at some certain condition.
import React, { useState } from 'react';
const api = {
key: "4f8e795dcd6dbf7b9f5276bff095ffc1",
base: "https://api.openweathermap.org/data/2.5/"
}
Creating Skeleton For App
Now let’s head to our return statement to create the skeleton for the weather app. Here we have added an input field with a class and placeholder. Then we have added another
for location-box and then added for location with an initial location to check the output. lastly we have added another div where we will add date where we will get date using datebuilder function.
`return (
type=”text”
className=”search-bar”
placeholder=”Search…”
/>