Skip to content

Instantly share code, notes, and snippets.

@eddyw
Created November 1, 2017 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eddyw/26b677853ce319d82a49b10489dd15da to your computer and use it in GitHub Desktop.
Save eddyw/26b677853ce319d82a49b10489dd15da to your computer and use it in GitHub Desktop.
Suck less at React (utilities #1): Switch Components
<section>
<SwitchIf test={this.props.section}>
<SwitchIf equals={1} test={this.props.isUserLogged}>
<SwitchWhen equals={true} render={<SectionUserLogged />} />
<SwitchWhen equals={false} render={<SectionUserNotLogged />} />
</SwitchIf>
<SwitchIf equals={2} test={this.props.isUserAdmin}>
<SwitchWhen equals={true} render={<SectionDashboard />} />
</SwitchIf>
<SwitchWhen equals={3} render={<SectionAbout />} />
<SwitchWhen equals={4} render={<SectionExample />} />
</SwitchIf>
</section>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment