Created
May 24, 2020 16:27
-
-
Save Deepak13245/d9a4bf4b6c623292dafd46318d5dfc22 to your computer and use it in GitHub Desktop.
Weather without hooks
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 React, { useEffect, useState } from "react"; | |
import PropTypes from "prop-types"; | |
import WeatherCard from './WeatherCard'; | |
import { getWeatherByLocationId } from "./connector"; | |
function WithoutHook({ locationId }) { | |
const [data, setData] = useState(null); | |
async function reload() { | |
try { | |
setData(null); | |
setData(await getWeatherByLocationId(locationId)); | |
} catch (e) { | |
console.error(e); | |
} | |
} | |
useEffect(() => { | |
reload(); | |
}, []); | |
return ( | |
<WeatherCard title="Without Hooks" data={data} reload={reload} /> | |
) | |
} | |
WithoutHook.propTypes = { | |
locationId: PropTypes.number.isRequired | |
}; | |
export default WithoutHook; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment