Note: This is using the new React Hooks API Proposal
which is subject to change until React 16.7 final.
You'll need to install react, react-dom, etc at ^16.7.0-alpha.0
Install
yarn add react-use-permissions
Usage
importusePermissionsfrom'../src';
constformat=hasPermissions=> {
switch (hasPermissions) {
// User has granted permissionscasetrue: {
return"Permissions granted";
}
// User has denied permissionscasefalse: {
return"Permissions denied";
}
// User will be prompted for permissionscasenull: {
return"Asking for permissions";
}
}
}
functionApp() {
consthasPermissions=usePermissions("geolocation");
constcontent=format(hasPermissions);
return<h1>{content}</h1>;
}
This looks helpful as React is now in Preview.
And would you add the link to the repo by chance?
You can show the repo using following 👇 syntax
, which will display the repo like this.
sergiodxa / react-use-permissions
React hook for Permissions API
react-use-permsissions
Install
Usage