vasanthk / react-bits

✨ React patterns, techniques, tips and tricks ✨
https://vasanthk.gitbooks.io/react-bits
Creative Commons Attribution 4.0 International
16.97k stars 1.1k forks source link

Another Approach for conditional Rendering #117

Open aniketsingh98571 opened 3 months ago

aniketsingh98571 commented 3 months ago

We can make use of switch statements if the conditions are too complex and long, Example:-

let componentToRender=null;
const admin=true
switch(admin){
   case true:
       componentToRender=<Admin/>
       break;
   case false:
       componentToRender=<User/>
}

return (
  {componentToRender}
)

File - https://github.com/vasanthk/react-bits/blob/master/patterns/1.conditionals-in-jsx.md