move function handle change city to context
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
"use client";
|
||||
|
||||
import { createContext, useContext, useState, useEffect } from "react";
|
||||
import citiesData from "@/data/city.json";
|
||||
|
||||
const ProvinceContext = createContext();
|
||||
|
||||
export const ProvinceProvider = ({ children }) => {
|
||||
const [hostName, setHostName] = useState("");
|
||||
const isProvinceInclude = citiesData.find(
|
||||
(city) => city.domain !== "nobat724.com" && hostName.includes(city.domain)
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof window !== "undefined") {
|
||||
setHostName(window.location.hostname);
|
||||
}
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<ProvinceContext.Provider value={{ isProvinceInclude }}>
|
||||
{children}
|
||||
</ProvinceContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export const useProvince = () => useContext(ProvinceContext);
|
||||
Reference in New Issue
Block a user