import { useState , useCallback } from 'react' ; import http from 'utils/httpInstance' ; const useAPI = ( ) => { const [ response , setResponse ] = useState ( null ) ; const [ loading , setLoading ] = useState ( false ) ; const [ error , setError ] = useState < any > ( null ) ; const callAPI = useCallback ( ( httpConfig , callback ) => { setLoading ( true ) ; setError ( null ) ; return http ( httpConfig ) . then ( res => { setLoading ( false ) ; setResponse ( res . data ) ; console . log ( res ) ; callback ( res ) ; } ) . catch ( ( err ) => { setError ( err ) ; setLoading ( false ) ; return Promise . reject ( err ) ; } ) ; } , [ ] ) ; return { loading , error , callAPI } ; } ; export default useAPI ;