
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
react-forecast-query
Advanced tools
Higher order React component delivering weather information from open weather api. Wrapper for forecast-query package.
A simple higher order component capable of injecting weather information from open weather api into a component
<div>
<input value={state.value} onInput={e => this.setState({ value: (e.target as HTMLInputElement).value })} />
<button onClick={() => this.setState(prevState => ({ apiKey: prevState.value }))}>Test component</button>
{state.apiKey && (
<WeatherDisplay
apiKey={state.apiKey}
label="Cloudy weather measurements"
query={['clouds', 'cloudy']}
by="hour"
loadingComponent={() => <div>Loading...</div>}
setup={forecast => forecast
.at(today, fourDaysFromNow)
.around(50.08804, 14.42076)
.units('metric')
.language('cz')}
/>
)}
</div>
import React, { FunctionComponent } from "react";
import { InjectedForecastResults } from "react-forecast-query";
import weatherEnhancer from "react-forecast-query";
export interface WeatherDisplayProps {
label: string;
}
const WeatherDisplay: FunctionComponent<WeatherDisplayProps & InjectedForecastResults> = props => (
<section>
<label>{props.label}</label>
<ul>
{props.data.clouds?.map(clouds => (
<li>
{clouds.date.toDateString()} {clouds.date.toTimeString()} - {clouds.value}
</li>
))}
</ul>
<ul>
{props.data.cloudy?.map(weather => (
<li>
<img src={props.forecast.icon(weather.icon)} />
<div>
{weather.description}
</div>
</li>
))}
</ul>
</section>
);
export default weatherEnhancer(WeatherDisplay);
Use setup props to add location, units, language and dates, then define a string list of information you want to receive.
List of information is derived from ".list()" function in forecast-query.
"By" parameter refers to how descriptive the list should be ("hour" delivers hourly weather updates, "day" daily ones).
"loadingComponent" will display whatever component you want when the api is loading information.
Added error component
Fix error component error reporting
Add support for gps geolocation in browser.
<WeatherDisplay
apiKey={state.apiKey}
label="Cloudy weather measurements"
query={['clouds', 'cloudy']}
by="hour"
loadingComponent={() => <div>Loading...</div>}
errorComponent={props => {
console.error(props.error);
return <div>Error!</div>
}}
geo // Try and get geolocation
updateGeo={1} // Updates every minute
setup={forecast => forecast
.at(today, fourDaysFromNow)
.units('metric') // No location setup needed
.language('cz')}
/>
Fixed a bug in typing of enhancer concerning Component class.
For more information about weather prediction from open weather api please visit: https://www.npmjs.com/package/forecast-query
If you find any bug or have an idea of how to improve this package, please file in an issue or a pull request
FAQs
Higher order React component delivering weather information from open weather api. Wrapper for forecast-query package.
The npm package react-forecast-query receives a total of 0 weekly downloads. As such, react-forecast-query popularity was classified as not popular.
We found that react-forecast-query demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.