Skip to content

Instantly share code, notes, and snippets.

@sibelius
Created January 16, 2020 16:49
Show Gist options
  • Save sibelius/593953c5f0ca8269668ded4c64f854be to your computer and use it in GitHub Desktop.
Save sibelius/593953c5f0ca8269668ded4c64f854be to your computer and use it in GitHub Desktop.
Component Base Role
const App = () => {
return (
<>
<RoleFlag user={user} roles={[ROLES.USER]}>
<AppUser />
</RoleFlag>
<RoleFlag user={user} roles={[ROLES.ADMIN]}>
<AppAdmin />
</RoleFlag>
</>
)
}
const RoleFlag = ({ user, roles, fallbackComponent }: Props) => {
if (hasRole(user, roles)) {
return children;
}
return fallbackComponent ? fallbackComponent : null;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment