UNPKG

@livelike/react-native

Version:

LiveLike React Native package

25 lines 593 B
import { useState } from 'react'; export function useApi(apiFunction) { const [data, setData] = useState(null); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(''); const onApi = () => { setIsLoading(true); return apiFunction().then(response => { setData(response); return response; }).catch(error => { setError(error); return Promise.reject(error); }).finally(() => { setIsLoading(false); }); }; return { data, error, isLoading, onApi }; } //# sourceMappingURL=useApi.js.map