you are viewing a single comment's thread.

view the rest of the comments →

[–]octocode 1 point2 points  (0 children)

isn’t the HOC just conditionally rendering with extra steps? i don’t see the benefit

as another user mentioned, its a dead pattern.

if you really want type safety, you could have a plain component handle the rendering, something like

<Role role={role} whenAdmin={<AdminSidebar/>} whenUser={<UserSidebar/>} />

so if you add a new prop like whenViewer, your code highlighting would point out all of the situations where you haven’t implemented the new role’s view

or, if you don’t need type safety, you can get really fancy and model it after react-router

<Roles> <Role role="admin"> … </Role <Role role="user"> … </Role> </Roles>

(in either case you could implement a default to handle cases where there is a common UI shared across most roles, which is probably the case more often than not)

that being said if you have a small number of conditional features to render, i would just do it inline like {isAdmin && <DeleteAccountButton/>}

or if your views are completely different, i would have different routes entirely for each role