From 55adfdf58700bb3c5edbda4be4fe4bd16114ab30 Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Fri, 24 May 2019 15:50:43 +0200 Subject: [PATCH] don't run the first time, only when refresh called --- www/utils/api.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/www/utils/api.js b/www/utils/api.js index 4b1c08b..10281d8 100644 --- a/www/utils/api.js +++ b/www/utils/api.js @@ -29,16 +29,17 @@ export const callAPI = async (ctxOrNull, { url, method, data }) => { else return response.data.body } -export const useCallAPI = (call) => { +export const useCallAPI = (call, automatic = false) => { const [data, setData] = useState(undefined) const refresh = () => { callAPI(null, call).then(setData) } - useEffect(() => { - refresh() - }, [0]) + if (automatic) + useEffect(() => { + refresh() + }, [0]) return [data, refresh] } \ No newline at end of file