mirror of
https://github.com/cupcakearmy/obolus.git
synced 2024-12-22 16:16:27 +00:00
don't run the first time, only when refresh called
This commit is contained in:
parent
44549d77ed
commit
55adfdf587
@ -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]
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user