Skip to content

Instantly share code, notes, and snippets.

@arun12209
Last active January 29, 2023 10:20
Embed
What would you like to do?
import { LightningElement } from 'lwc';
export default class Weather extends LightningElement {
city = '';
temperature = '';
humidity = '';
description = '';
handleCityChange(event) {
this.city = event.target.value;
}
async getWeather() {
const apiKey = 'your-api-key';
const url = `https://api.openweathermap.org/data/2.5/weather?q=${this.city}&appid=${apiKey}`;
const response = await fetch(url);
const data = await response.json();
this.temperature = data.main.temp;
this.humidity = data.main.humidity;
this.description = data.weather[0].description;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment