Permission-based view restrictions for React.
- React >= 16.8.0
yarn add react-restricted react react-dom
import { RestrictedProvider, RestrictedView } from "react-restricted";
function ViewExample() {
return (
<RestrictedProvider permissions={["somePermission"]}>
<RestrictedView requiredPermission="somePermission">
<SomeComponent />
</RestrictedView>
</RestrictedProvider>
);
}
import { RestrictedProvider, RestrictedConsumer } from "react-restricted";
function ContextExample() {
return (
<RestrictedProvider permissions={["somePermission"]}>
<RestrictedConsumer>
{({ hasPermission }) =>
hasPermission("somePermission") ? <SomeComponent /> : <SomeOtherComponent />
}
</RestrictedConsumer>
</RestrictedProvider>
);
}
import { useRestricted } from "react-restricted";
function HookExample() {
const { hasPermission } = useRestricted();
return hasPermission("somePermission")
? <SomeComponent>
: <SomeOtherComponent />
}
Please read our guidelines.
See LICENSE.