What am I doing wrong with my if statements?

by andretg12   Last Updated August 14, 2019 04:26 AM

I'm porting a website I had build already for another project into React and wanted to set a state for my navbar and was trying to set up my conditionals to render my pages first but it keeps throwing syntax error

I tried changing the {} enclosing to if to () to see if that did anything. I also tried wrapping my if inside {()} and nothing

class App extends Component {
  state = {
    page: 0,
  }
  setPageChange = () => {
    setState({ page: props.key })
  }

  render() {
    return (
      <div>
        <NavBar />
        {if (this.state.page === 1) {
          return (<Products />)
        } else if(this.state.page === 2) {
          return (<Contact />)
        } else {
          <Landing />
        }}
        <Footer />
      </div>
    );
  }
}


Related Questions


Updated June 21, 2015 23:11 PM

Updated April 22, 2015 00:11 AM

Updated July 13, 2015 13:11 PM

Updated August 20, 2018 22:26 PM

Updated November 05, 2018 22:26 PM