1.0.3 • Published 3 years ago

react-permission-component v1.0.3

Weekly downloads
6
License
MIT
Repository
github
Last release
3 years ago

📜 About

react-permission-component is a simple component for React.js. It allows you to render a component or not based on specified permissions, for example render different components whether a user is admin or not.

💾 Install

npm install --save react-permission-component

💻 How To Use

import React from 'react';
import PermissionWrapper from "./PermissionComponent";

const Example = () => {
    return(
        <div>
            <PermissionWrapper requiredPermissions={{isAdmin : true, hasDashboardAccess : true}} 
                               permissions={{hasAdmin:true}}  
                               orOperatorActive={true} 
                               disallowedComponent={<h1>Not available</h1>}>
                <h1>Available!</h1>
            </PermissionWrapper>
        </div>
    )
}

The children of this wrapper will only be rendered if the key-value pairs in the required permissions match the permissions supplied to the component.

📖 Available Props

PropDescriptionRequired
requiredPermissionsAn object with key-value pairs which describe the required permissionstrue
permissionsThe supplied permissions of the usertrue
disallowedComponentThe component that will be rendered in case permission is deniedfalse
orOperatorActiveIf true, in case the user has at least one permission, children will be renderedfalse
customValidationFunction(permissions,requiredPermissions,orOperatorActive) as parameters If the function returns true, the children will be renderedfalse
1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago