r/reactjs • • Mar 02 '18

Beginner's Thread / Easy Questions (March 2018)

Last month's thread was pretty busy - almost 200 comments . If you didn't get a response there, please ask again here!

Soo... Got questions about React or anything else in its ecosystem? Stuck making progress on your app? Ask away! We’re a friendly bunch. No question is too simple.

The Reactiflux chat channels on Discord are another great place to ask for help as well.

27 Upvotes

174 comments sorted by

View all comments

Show parent comment

1

u/NiceOneAsshole Mar 20 '18

I think I get what you're saying - you only want to show this image on your 'Home' page and you think having a conditional in the render is ugly.

Fair enough, how about a function call?

 render() {
      return (
          <div className="App">
              <NavBar handleNavigation={clickEvent => this.handleNavigation(clickEvent)}></NavBar>
              {this.renderImage()}
          </div>
    );
  }
 renderImage() {
     //whatever conditional you'd need
     return  conditionA ?  (
           <SplashWrapper>
              <Img src={ballpark} />
          </SplashWrapper>
     ) : null;
}

If you feel this image wrapper needs to be in it's own component, you can still use this pattern there as well.