Skip to content

Instantly share code, notes, and snippets.

@francois-roget
Created May 25, 2021 06:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save francois-roget/d0f716f28add2173c9a916a488efd2e3 to your computer and use it in GitHub Desktop.
Save francois-roget/d0f716f28add2173c9a916a488efd2e3 to your computer and use it in GitHub Desktop.
import {useContext, useState} from 'react';
import PermissionContext from "./PermissionContext";
import {Permission} from "../Types";
const usePermission = (permission: Permission) => {
const [loading, setLoading] = useState(true);
const [allowed, setAllowed] = useState<boolean>();
const {isAllowedTo} = useContext(PermissionContext);
isAllowedTo(permission).then((allowed) => {
setLoading(false);
setAllowed(allowed);
})
return [loading, allowed]
}
export default usePermission;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment