jeudi 27 septembre 2018

react native if else statement won't run function automatically

trying to run a function on a if else statement in react native, however if I just call it straight up like this.removeAlert() I get an infinite loop crash because of calling setState. I read that you should call it within a function, which works fine in onPress functions, but for me its not working outside of that.

  class Settingscontainer extends Component {
  constructor() {
   super();
   this.removeAlert = this.removeAlert.bind(this);
  }
  removeAlert = () => {
    console.log("please work");
    // this.setState({ successAlert: false });
  };

  render() {
    this.props.isFocused
      ? console.log("Focused") // console.log working
      : () => {                // not working
          this.removeAlert();
        };
    return(<View>code...</View>
    )  
    }}
     

Aucun commentaire:

Enregistrer un commentaire