From a2a6c7fdb96ebae91663d387ef5aee97dd6a5431 Mon Sep 17 00:00:00 2001 From: harukin-expo-dev-env Date: Sun, 3 Aug 2025 08:22:51 +0000 Subject: [PATCH] =?UTF-8?q?useeffect=E9=96=A2=E4=BF=82=E3=81=AE=E6=A9=9F?= =?UTF-8?q?=E8=83=BD=E6=9C=80=E9=81=A9=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.js | 4 +++- stateBox/useAllTrainDiagram.js | 24 +++++++++++++----------- stateBox/useAreaInfo.js | 4 +++- stateBox/useCurrentTrain.js | 4 +++- stateBox/useUserPosition.tsx | 4 +++- 5 files changed, 25 insertions(+), 15 deletions(-) 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 (