mardi 4 juin 2019

correct way to insert an if/else statement inside const in React Native?

I keep getting a synax error and I'm not sure how to do this any other way:

    const new_datas = [
      if(this.state.username != '') {
      {
        name: "Plaza",
        route: "TabNav",
        icon: require("../img/plaza_party.png"),
        bg: "#C5F442"
      },
      {
        name: `${this.state.thefirstname}'s Profile`,
        route: "ProfileScreen",
        icon: require("../img/pass.png"),
        bg: "#C5F442"
      },
    }
    else{
      {
        name: "Plaza",
        route: "TabNav",
        icon: require("../img/plaza_party.png"),
        bg: "#C5F442"
      },
      {
        name: "Login/Sign Up",
        route: "LoginScreen",
        icon: require("../img/pass.png"),
        bg: "#477EEA",
      },
    }
  ];

Basically what should happen is once the username is stored in state it should update the contents then switch from Login/Signup to this.state.firstname Profile. Is there any correct way to achieve this?

Aucun commentaire:

Enregistrer un commentaire