Skip to content

Instantly share code, notes, and snippets.

@francois-roget
Last active May 25, 2021 06:23
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/139a3cffd41798e91e7bb76290fea6db to your computer and use it in GitHub Desktop.
Save francois-roget/139a3cffd41798e91e7bb76290fea6db to your computer and use it in GitHub Desktop.
import React from 'react';
import {Permission} from "../Types";
type PermissionContextType = {
isAllowedTo: (permission: Permission) => boolean;
}
// Default behaviour for the Permission Provider Context
// i.e. if for whatever reason the consumer is used outside of a provider.
// The permission will not be granted unless a provider says otherwise
const defaultBehaviour: PermissionContextType = {
isAllowedTo: () => false
}
// Create the context
const PermissionContext = React.createContext<PermissionContextType>( defaultBehaviour);
export default PermissionContext;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment