Skip to content

Commit

Permalink
Add isLoading to useRetrieveStats hook
Browse files Browse the repository at this point in the history
  • Loading branch information
pH-7 authored Dec 2, 2023
1 parent 0072a41 commit 3dadf61
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion utils/useRetrieveStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@ import { useState, useEffect } from 'react';
export default (apiUrl) => {
const [stats, setStats] = useState();
const [isError, setIsError] = useState(false);
const [isLoading, setIsLoading] = useState(false);

const fetchData = async () => {
try {
setIsError(false);
setIsLoading(true);

const results = await fetch(`${apiUrl}`);
console.log(`Fetching data for: ${apiUrl}`);
setStats(results.json());
} catch (err) {
setIsError(err)
} finally {
setIsLoading(false);
}
};

Expand All @@ -21,6 +26,7 @@ export default (apiUrl) => {

return {
stats,
isError
isError,
isLoading
};
}

0 comments on commit 3dadf61

Please sign in to comment.