29 lines
890 B
TypeScript
29 lines
890 B
TypeScript
import { useState, useEffect } from "react";
|
|
import { useStationList } from "@/stateBox/useStationList";
|
|
|
|
/**
|
|
* 停車駅IDリストを生成するカスタムフック
|
|
*/
|
|
export const useStopStationList = (trainDataWithThrough: string[]) => {
|
|
const { stationList } = useStationList();
|
|
const [stopStationIDList, setStopStationList] = useState<string[][]>([]);
|
|
|
|
useEffect(() => {
|
|
const x = trainDataWithThrough.map((i) => {
|
|
const [station] = i.split(",");
|
|
const Stations = stationList.map((a) =>
|
|
a.filter((d) => d.StationName == station)
|
|
);
|
|
const StationNumbers =
|
|
Stations &&
|
|
Stations.reduce((newArray, e) => {
|
|
return newArray.concat(e);
|
|
}, []).map((d) => d.StationNumber);
|
|
return StationNumbers;
|
|
});
|
|
setStopStationList(x);
|
|
}, [trainDataWithThrough, stationList]);
|
|
|
|
return stopStationIDList;
|
|
};
|