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,13 +29,14 @@ 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)
}
if (automatic)
useEffect(() => {
refresh()
}, [0])