diff --git a/App.js b/App.js index 4fec0f5..2493539 100644 --- a/App.js +++ b/App.js @@ -32,7 +32,9 @@ if (Platform.OS === "android") { } export default function App() { - useEffect(() => UpdateAsync(), []); + useEffect(() => { + UpdateAsync(); + }, []); const ProviderTree = buildProvidersTree([ AllTrainDiagramProvider, diff --git a/stateBox/useAllTrainDiagram.js b/stateBox/useAllTrainDiagram.js index 7806f8a..c86c638 100644 --- a/stateBox/useAllTrainDiagram.js +++ b/stateBox/useAllTrainDiagram.js @@ -16,11 +16,13 @@ export const AllTrainDiagramProvider = ({ children }) => { const [allTrainDiagram, setAllTrainDiagram] = useState(trainList); const [allCustonTrainData, setAllCustonTrainData] = useState([]); // カスタム列車データ const [keyList, setKeyList] = useState(); // 第二要素 - useEffect( - () => allTrainDiagram && setKeyList(Object.keys(allTrainDiagram)), - [allTrainDiagram] - ); - const getTrainDiagram = () => fetch("https://n8n.haruk.in/webhook/JR-shikoku-diagram-migrate-original") + useEffect(() => { + if (allTrainDiagram && Object.keys(allTrainDiagram).length > 0) + setKeyList(Object.keys(allTrainDiagram)); + else setKeyList([]); + }, [allTrainDiagram]); + const getTrainDiagram = () => + fetch("https://n8n.haruk.in/webhook/JR-shikoku-diagram-migrate-original") .then((res) => res.json()) .then((res) => res.data) .then((res) => { @@ -42,12 +44,13 @@ export const AllTrainDiagramProvider = ({ children }) => { alert("初回の路線情報の取得に失敗しました。"); }); }); - - useEffect(getTrainDiagram, []); + + useEffect(() => { + getTrainDiagram(); + }, []); useInterval(getTrainDiagram, 30000); //30秒毎に全在線列車取得 - - const getCustomTrainData = ()=>{ + const getCustomTrainData = () => { fetch("https://n8n.haruk.in/webhook/jr-shikoku-position-custom-datalist") .then((res) => res.json()) .then((res) => { @@ -56,8 +59,7 @@ export const AllTrainDiagramProvider = ({ children }) => { .catch(() => { alert("カスタム列車データの取得に失敗しました。"); }); - } - + }; useEffect(() => { // カスタム列車データの取得 diff --git a/stateBox/useAreaInfo.js b/stateBox/useAreaInfo.js index bdc9a0f..cc9df4d 100644 --- a/stateBox/useAreaInfo.js +++ b/stateBox/useAreaInfo.js @@ -378,7 +378,9 @@ export const AreaInfoProvider = ({ children }) => { ); }); }; - useEffect(getAreaData, []); + useEffect(() => { + getAreaData(); + }, []); useInterval(getAreaData, 60000); //60秒毎に全在線列車取得 return ( { webview.current?.injectJavaScript(i); }; - useEffect(getCurrentTrain, []); //初回だけ現在の全在線列車取得 + useEffect(() => { + getCurrentTrain(); + }, []); //初回だけ現在の全在線列車取得 useInterval(getCurrentTrain, 15000); //15秒毎に全在線列車取得 diff --git a/stateBox/useUserPosition.tsx b/stateBox/useUserPosition.tsx index 2b4cb83..724d5bf 100644 --- a/stateBox/useUserPosition.tsx +++ b/stateBox/useUserPosition.tsx @@ -58,7 +58,9 @@ export const UserPositionProvider: FC = ({ children }) => { if (Platform.OS == "web") return; getLocationPermission(); }, []); - useEffect(getCurrentPosition, [locationStatus]); + useEffect(() => { + getCurrentPosition(); + }, [locationStatus]); useInterval(getCurrentPosition, 5000); return (