Skip to content

Instantly share code, notes, and snippets.

@iswanj
Created August 29, 2018 05:17
Show Gist options
  • Save iswanj/41dee7caed092016a0b8cdaece8be012 to your computer and use it in GitHub Desktop.
Save iswanj/41dee7caed092016a0b8cdaece8be012 to your computer and use it in GitHub Desktop.
Permission handle
import React from "react";
const isPremited = (roles, type) => {
// premission check logic
return ...;
}
export default () => {
let { roles, permissionId, children } = this.props;
if(!isPremited(roles, permissionId)) return </div>;
return (
<React.Fragment>{children}</React.Fragment>
);
}
import React from "react";
import Access from "./Access";
export default class TodoList extends React.Component {
render() {
return (
<div>
<Access roles={this.props.roles} permissionId="VIEW_TODO" >
<ToDos />
</Access>
<Access roles={this.props.roles} permissionId="ADD_TODO" >
<AddTodo />
</Access>
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment