vasanthk / react-bits

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

Another Approach for conditional Rendering #117

Open aniketsingh98571 opened 1 month ago

aniketsingh98571 commented 1 month 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