diff --git a/hooks/useFetch.jsx b/hooks/useFetch.jsx index 6ac43122..81cc4432 100644 --- a/hooks/useFetch.jsx +++ b/hooks/useFetch.jsx @@ -1,6 +1,6 @@ import { useEffect, useReducer, useState } from 'react'; -const useFetch = (url, { initialValue } = {}) => { +const useFetch = (url, { initialValue, onSuccess } = {}) => { const [render, refetch] = useReducer((pre) => !pre, true); const [data, setData] = useState(initialValue); const [isFetching, setIsFetching] = useState(true); @@ -25,6 +25,10 @@ const useFetch = (url, { initialValue } = {}) => { }; }, [url, render]); + useEffect(() => { + if (onSuccess) onSuccess(data); + }, [onSuccess, data]); + return { data, isFetching, isError, refetch }; };