HOC is not an anti-pattern - it is HOF if we consider any component as a function, but hooks break the main FP rule - the function purity and I consider it as a side-effect. I agree with you, the best solution for this example are routers and HOC should be used for something else.
I prefer to create some helper functions which can be used across the project:
constDefaultSettings=()=>(<p>What the Hell Are You?</p>)constselectSettings=select(when(`admin`,AdminSettings),when(`user`,UserSettings),when(`guest`,GuestSettings),()=>DefaultSettings)constUserSettings=({userRole,username})=>{constSettings=selectSettings(userRole)return(<div><h1>Settings</h1><Settingsusername={username}/></div>)}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
HOC is not an anti-pattern - it is HOF if we consider any component as a function, but hooks break the main FP rule - the function purity and I consider it as a side-effect. I agree with you, the best solution for this example are routers and HOC should be used for something else.
I prefer to create some helper functions which can be used across the project:
and use them: