🎨 Configure standardJS

This commit is contained in:
divlo
2020-08-03 12:04:07 +02:00
parent e22e62a749
commit 58f47c7480
120 changed files with 12271 additions and 10025 deletions

View File

@ -1,31 +1,30 @@
import { useEffect, useState } from 'react';
import api from '../utils/api';
import { useEffect, useState } from 'react'
import api from '../utils/api'
/**
* @param {String} url
* @param {*} defaultData
* @param {String} method
* @param {Object} options
* @param {String} url
* @param {*} defaultData
* @param {String} method
* @param {Object} options
*/
function useAPI(url, defaultData = [], method = "get", options = {}) {
function useAPI (url, defaultData = [], method = 'get', options = {}) {
const [isLoading, setIsLoading] = useState(true)
const [data, setData] = useState(defaultData)
const [hasError, setHasError] = useState(false)
const [isLoading, setIsLoading] = useState(true);
const [data, setData] = useState(defaultData);
const [hasError, setHasError] = useState(false);
useEffect(() => {
api[method](url, options)
.then((result) => {
setData(result.data)
setIsLoading(false)
})
.catch((error) => {
setHasError(true)
console.error(error)
})
}, [])
useEffect(() => {
api[method](url, options)
.then((result) => {
setData(result.data);
setIsLoading(false);
})
.catch((error) => {
setHasError(true);
console.error(error);
});
}, []);
return [isLoading, data, hasError];
return [isLoading, data, hasError]
}
export default useAPI;
export default useAPI