Event to use to trigger state update after componentDidMount

I am running into a glitch just in android for my react native app where … Read more Event to use to trigger state update after componentDidMount

I am running into a glitch just in android for my react native app where something is blocking the usual Android context menu from being enabled. I am able to overcome this by setting the editable property on TextInput to false initially, and then setting it to true with a 2 second delay within componentDidMount(), like so:

const wait = (timeout) => {
  return new Promise(resolve => setTimeout(resolve, timeout));
}

class GoalsTab extends React.PureComponent {
  constructor(props) {
    super(props);
  }

  state = {
    editable: false,
  }

  componentDidMount() {
    wait(2000).then(() => {
      if(this.state.editable === false) {
        this.setState({ editable: true });
      }
    });
  }
}

This works, but obviously I’d rather not rely on a time delay, which is not guaranteed to work in all cases. My question is, after componentDidMount() fires, what events could I use to set editable to true only when that event fires? By the way, I tried componentDidUpdate, but this does not work, probably because it fires to quickly, and whatever is blocking the functionality is still happening.

Source: React – Stack Overflow



Leave a Reply

Your email address will not be published. Required fields are marked *