Created
May 24, 2020 16:31
-
-
Save Deepak13245/cb1af99bf129f753c192a94a86b3ba46 to your computer and use it in GitHub Desktop.
Weather Hook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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