Skip to content

Instantly share code, notes, and snippets.

@andrit
Created September 17, 2018 14:06
Show Gist options
  • Save andrit/8f5edc9d97a187045a3bf28aecc5093b to your computer and use it in GitHub Desktop.
Save andrit/8f5edc9d97a187045a3bf28aecc5093b to your computer and use it in GitHub Desktop.
using a switch in a custom method in react to do conditionalrender
renderSectionOnState = () =>{
     switch(this.state.activeSection){
      case 'introsection':
        return <IntroScreen 
                  handleSwitchSection={this.handleSwitchSection} 
                  activeSection={this.state.activeSection} />
      break;
      case 'basicinfosection':
        return <BasicInfo 
                  handleSwitchSection={this.handleSwitchSection} 
                  activeSection={this.state.activeSection} />
      break;
      case 'extrainfosection':
        return <ExtraInfo
                  activeSection={this.state.activeSection}
                  handleAddLikes={this.handleAddLike}
                  handleAddCategories={this.handleAddCategory}
                  selectedLikes={this.state.selectedLikes}
                  selectedCategories={this.state.selectedCategories}
                  handleAcct={this.handleAcct}
                   />
      break;
    }
  }

then in the return:

{this.renderSectionOnState()}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment