Skip to content

Instantly share code, notes, and snippets.

@Deepak13245
Created May 24, 2020 16:31
Show Gist options
  • Save Deepak13245/cb1af99bf129f753c192a94a86b3ba46 to your computer and use it in GitHub Desktop.
Save Deepak13245/cb1af99bf129f753c192a94a86b3ba46 to your computer and use it in GitHub Desktop.
Weather Hook
import {useState, useEffect} from 'react';
import {getWeatherByLocationId} from './connector';
function useWeather(locationId){
const [data, setData] = useState(null);
async function reload() {
try {
setData(null);
setData(await getWeatherByLocationId(locationId));
} catch (e) {
console.error(e);
}
}
useEffect(() => {
reload();
}, []);
return [data, reload];
}
export default useWeather;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment