Skip to content
Snippets Groups Projects
Verified Commit 62493e9d authored by Defendi Alberto's avatar Defendi Alberto
Browse files

Return isLoading while api fetch.

The return data of this hooks needs to be polished when AuthContext will
be removed.
parent fadf957b
No related branches found
No related tags found
2 merge requests!60New component to search senior (see #12). Enhance responsiveness and solve #10 and #11,!57Replace context with api.
Pipeline #12606 passed
......@@ -4,8 +4,10 @@ import { useEffect, useState } from 'react';
export const useRole = (): [
string,
React.Dispatch<React.SetStateAction<string>>,
boolean,
] => {
const [role, setRole] = useState('');
const [isLoading, setIsLoading] = useState(true);
useEffect(() => {
let isMounted = true;
......@@ -14,11 +16,12 @@ export const useRole = (): [
getRole().then((responseRole) => {
if (isMounted) {
setRole(responseRole);
if (role !== null) setIsLoading(false);
}
});
return () => {
isMounted = false;
};
}, []);
return [role, setRole];
return [role, setRole, isLoading];
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment