Created
January 16, 2020 16:49
-
-
Save sibelius/593953c5f0ca8269668ded4c64f854be to your computer and use it in GitHub Desktop.
Component Base Role
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const App = () => { | |
return ( | |
<> | |
<RoleFlag user={user} roles={[ROLES.USER]}> | |
<AppUser /> | |
</RoleFlag> | |
<RoleFlag user={user} roles={[ROLES.ADMIN]}> | |
<AppAdmin /> | |
</RoleFlag> | |
</> | |
) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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