don't run the first time, only when refresh called

This commit is contained in:
cupcakearmy 2019-05-24 15:50:43 +02:00
parent 44549d77ed
commit 55adfdf587

View File

@ -29,16 +29,17 @@ export const callAPI = async (ctxOrNull, { url, method, data }) => {
else return response.data.body else return response.data.body
} }
export const useCallAPI = (call) => { export const useCallAPI = (call, automatic = false) => {
const [data, setData] = useState(undefined) const [data, setData] = useState(undefined)
const refresh = () => { const refresh = () => {
callAPI(null, call).then(setData) callAPI(null, call).then(setData)
} }
useEffect(() => { if (automatic)
refresh() useEffect(() => {
}, [0]) refresh()
}, [0])
return [data, refresh] return [data, refresh]
} }