refactor: change apiKey variable to a function for better encapsulation in WeatherCard component
This commit is contained in:
@@ -5,7 +5,7 @@ import Cookies from "js-cookie";
|
||||
|
||||
const WeatherCard: React.FC = () => {
|
||||
const [city, setCity] = useState("");
|
||||
const apiKey = Cookies.get("apiKey") || "";
|
||||
const getAPIKey = () => Cookies.get("apiKey") || "";
|
||||
|
||||
const handleCityChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
setCity(event.target.value);
|
||||
@@ -13,7 +13,7 @@ const WeatherCard: React.FC = () => {
|
||||
|
||||
const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
fetchWeather(city, apiKey);
|
||||
fetchWeather(city, getAPIKey());
|
||||
};
|
||||
|
||||
return (
|
||||
|
Reference in New Issue
Block a user