From b8d543e1c1d41246019370edf9e4e0b10890fe1d Mon Sep 17 00:00:00 2001 From: ChrQR Date: Sat, 11 May 2024 01:21:34 +0200 Subject: [PATCH] moved context to separate file and imported --- app/page.tsx | 7 +------ components/LocationSearch.tsx | 2 +- components/WeatherNow.tsx | 2 +- context/LocationContext.tsx | 8 ++++++++ 4 files changed, 11 insertions(+), 8 deletions(-) create mode 100644 context/LocationContext.tsx diff --git a/app/page.tsx b/app/page.tsx index bda70e1..7787c08 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -4,12 +4,7 @@ import WeatherNow from '../components/WeatherNow' import { createContext, useState } from 'react'; import { defaultGeoLocation } from './defaultState'; import { LocationContextType, coordType } from '@/types/types'; - - -export const LocationContext = createContext({ - geoLocation: defaultGeoLocation, - setGeoLocation: () => {} // Default function, does nothing -}); +import { LocationContext } from '@/context/LocationContext'; export default function Home() { const [geoLocation, setGeoLocation] = useState(defaultGeoLocation); diff --git a/components/LocationSearch.tsx b/components/LocationSearch.tsx index 2703821..94a90ed 100644 --- a/components/LocationSearch.tsx +++ b/components/LocationSearch.tsx @@ -1,7 +1,7 @@ "use client"; import React, { useContext, useState } from "react"; import { getLocation } from "@/app/actions"; -import { LocationContext } from "@/app/page"; +import { LocationContext } from "@/context/LocationContext"; export default function LocationSearch() { const [searchLocation, setSearchLocation] = useState(""); diff --git a/components/WeatherNow.tsx b/components/WeatherNow.tsx index 1395dec..a2e05e4 100644 --- a/components/WeatherNow.tsx +++ b/components/WeatherNow.tsx @@ -5,7 +5,7 @@ import Temperature from "./Temperature"; import { HourlyCardPropType, HourlyForecast, WeatherContextType } from "@/types/types"; import { createContext, useContext, useEffect, useState } from "react"; import { defaultHourlyForecast } from "@/app/defaultState"; -import { LocationContext } from "@/app/page"; +import { LocationContext } from "@/context/LocationContext"; import WeatherHero from "./WeatherHero"; import HourlyCard from "./HourlyCard/HourlyCard"; diff --git a/context/LocationContext.tsx b/context/LocationContext.tsx new file mode 100644 index 0000000..b10d282 --- /dev/null +++ b/context/LocationContext.tsx @@ -0,0 +1,8 @@ +import { createContext } from 'react'; +import { LocationContextType, coordType } from '@/types/types'; +import { defaultGeoLocation } from '../app/defaultState'; + +export const LocationContext = createContext({ + geoLocation: defaultGeoLocation, + setGeoLocation: () => {} // Default function, does nothing +});