why is this a React hook?
this is a simplified version of the production/real world version
You can consume roles
from context/redux/relay or other place to improve dx and void bugs
why is this a React hook?
this is a simplified version of the production/real world version
You can consume roles
from context/redux/relay or other place to improve dx and void bugs
const App = ({ user }) => { | |
const { hasRole } = usePermission(user); | |
return ( | |
<span>Hello</span> | |
{hasRole('PRODUCT:CREATE') && <button>Create Product</button> | |
); | |
} |
const usePermission = (user: UserPermission_user) => { | |
const hasRole = (role: string) => { | |
return user.roles.includes(role); | |
}; | |
return { | |
hasRole | |
}; | |
}; |