This commit is contained in:
@@ -17,20 +17,20 @@ type Zone = {
|
||||
province: number;
|
||||
};
|
||||
export default function LocationSelector({ provinces }: Props) {
|
||||
let [provinceId, setProvinceId] = useState<number | undefined>(undefined);
|
||||
let [amphurList, setAmphurList] = useState<Zone[] | undefined>(undefined);
|
||||
let [amphurId, setAmphurId] = useState<number | undefined>(undefined);
|
||||
const [provinceId, setProvinceId] = useState<number | undefined>(undefined);
|
||||
const [amphurList, setAmphurList] = useState<Zone[] | undefined>(undefined);
|
||||
const [amphurId, setAmphurId] = useState<number | undefined>(undefined);
|
||||
const locationContext = useContext(LocationContext);
|
||||
function setProvince(_id: string) {
|
||||
let id = parseInt(_id);
|
||||
const id = parseInt(_id);
|
||||
setProvinceId(id);
|
||||
let province = provinces.find((p) => p.id == id);
|
||||
const province = provinces.find((p) => p.id == id);
|
||||
if (province == undefined) return;
|
||||
setAmphurList(province.zones);
|
||||
setAmphurId(undefined);
|
||||
}
|
||||
function setAmphur(_id: string) {
|
||||
let id = parseInt(_id);
|
||||
const id = parseInt(_id);
|
||||
setAmphurId(id);
|
||||
}
|
||||
useEffect(() => {
|
||||
|
||||
@@ -21,8 +21,8 @@ export default function LocationContextProvider({
|
||||
}: {
|
||||
children?: ReactNode;
|
||||
}) {
|
||||
let zone = useState<number | undefined>(undefined);
|
||||
let province = useState<number | undefined>(undefined);
|
||||
const zone = useState<number | undefined>(undefined);
|
||||
const province = useState<number | undefined>(undefined);
|
||||
|
||||
return (
|
||||
<LocationContext.Provider value={{ zone, province }}>
|
||||
|
||||
Reference in New Issue
Block a user