Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

react show view based on role permission

import PropTypes from 'prop-types';
import { connect } from 'react-redux';

const ShowForPermissionComponent = (props) => {
    const couldShow = props.userPermissions.includes(props.permission);
    return couldShow ? props.children : null;
};

ShowForPermissionComponent.propTypes = {
    permission: PropTypes.string.isRequired,
    userPermissions: PropTypes.array.isRequired
};


const mapStateToProps = state => ({
    userPermissions: state.user.permission //<--- here you will get permissions for your user from Redux store
});

export const ShowForPermission = connect(mapStateToProps)(ShowForPermissionComponent);
Comment

react show view based on role permission

import React from 'react';
import { ShowForPermission } from './ShowForPermission';

cons MyComponent = props => {
   return (
        <div>
            <ShowForPermission permission="DELETE">
                <button>Delete</button>
            </ShowForPermission>
        </div>
   );
}

Comment

PREVIOUS NEXT
Code Example
Javascript :: babel compile files empty 
Javascript :: change array range value javascript 
Javascript :: CodePen Home Load iframe on click 
Javascript :: getusermedia close stream 
Javascript :: gsheet formula get last item in column 
Javascript :: nuxt history back 
Javascript :: js.l2 
Javascript :: promise .then javascript 
Javascript :: clear input fild 
Javascript :: how to pass a component as a prop in react 
Javascript :: latex sum two lines subscript 
Javascript :: como instalar la nueva version de node-js en ubuntu 
Javascript :: javascript prevent right click 
Javascript :: get all dates between two dates in moment js 
Javascript :: jest mock call 
Javascript :: href before onclick js 
Javascript :: search an array with regex javascript find 
Javascript :: string js 
Javascript :: compare if strings are equal javascript 
Javascript :: express ubuntu ERR_CONNECTION_REFUSED 
Javascript :: phantomjs in angular 
Javascript :: sort array javascript 
Javascript :: monaco editor cdn 
Javascript :: javascript switch statement 
Javascript :: moyenne javascript 
Javascript :: slice 
Javascript :: calculate time in seconds javascript angular 
Javascript :: dynamic classes in react 
Javascript :: Variadic function in javascript 
Javascript :: react google places auto complete example 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =