Skip to content

Another Approach for conditional Rendering #117

@aniketsingh98571

Description

@aniketsingh98571

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions