React-native: [Android] setTimeout inside componentDidMount never fires.

Created on 12 Dec 2015  路  6Comments  路  Source: facebook/react-native

I am registering a setTimeout inside componentDidMount for several Components . What I observe is , componentDidMount does gets executed. but the setTimeout callbacks never.

componentDidMount() {
    console.log("Option list Mounted")
    setTimeout(() => {
      this.refs.OPTIONLIST.measure(this.getMeasureAndUpdateState);
    },0);
  }

Node Version 4.1.1
ReactNative : 0.16

Thanks.

Locked

Most helpful comment

This bug was closed without justification.

The original problem was about the callback not firing at all, rather than firing when it shouldn't.

In addition, React components are not the only parties that might use setTimeout() - third party RN-agnostic libraries might do so too, and there is no way to make them use the mixin without rewriting them.

setTimeout() must do what specs say it should do, that is, actually cause the callback to be fired after the given amount of time with 100% certainty, unless clearTimeout() was used. This bug should be reopened and remain open until _this_ issue is resolved, rather than some vaguely similar issue.

All 6 comments

Hey gs-akhan, thanks for reporting this issue!

React Native, as you've probably heard, is getting really popular and truth is we're getting a bit overwhelmed by the activity surrounding it. There are just too many issues for us to manage properly.

  • If this is a feature request or a bug that you would like to be fixed by the team, please report it on Product Pains. It has a ranking feature that lets us focus on the most important issues the community is experiencing.
  • If you don't know how to do something or not sure whether some behavior is expected or a bug, please ask on StackOverflow with the tag react-native or for more real time interactions, ask on Discord in the #react-native channel.
  • We welcome clear issues and PRs that are ready for in-depth discussion; thank you for your contributions!

I cannot reproduce this with RN master.

componentDidMount() {
    setTimeout(
      () => console.log("componentDidMount with timeout!"),
      0
    )
  },
12-14 08:56:24.460 2256-3064/com.scrollviewtest I/ReactNativeJS: componentDidMount with timeout!

@theoriginalgri Register multiple and I am facing this on Android only.. However I will try to setup a example.

@gs-akhan have you looked at https://facebook.github.io/react-native/docs/timers.html#timermixin

We strongly discourage using the global setTimeout(...) and recommend instead that you use this.setTimeout(...) provided by react-timer-mixin. This will eliminate a lot of hard work tracking down bugs, such as crashes caused by timeouts firing after a component has been unmounted.

@gs-akhan Feel free to open this up again if you still have problems when switching to this.setTimeout.

This bug was closed without justification.

The original problem was about the callback not firing at all, rather than firing when it shouldn't.

In addition, React components are not the only parties that might use setTimeout() - third party RN-agnostic libraries might do so too, and there is no way to make them use the mixin without rewriting them.

setTimeout() must do what specs say it should do, that is, actually cause the callback to be fired after the given amount of time with 100% certainty, unless clearTimeout() was used. This bug should be reopened and remain open until _this_ issue is resolved, rather than some vaguely similar issue.

Was this page helpful?
0 / 5 - 0 ratings