Skip to content

Instantly share code, notes, and snippets.

@Deepak13245
Created May 24, 2020 16:27
Show Gist options
  • Save Deepak13245/d9a4bf4b6c623292dafd46318d5dfc22 to your computer and use it in GitHub Desktop.
Save Deepak13245/d9a4bf4b6c623292dafd46318d5dfc22 to your computer and use it in GitHub Desktop.
Weather without hooks
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