search

Home  >  Q&A  >  body text

Why doesn't clearInterVal work?

Using react to encapsulate a library that returns to the top.

滿天的星座滿天的星座2750 days ago849

reply all(3)I'll reply

  • 漂亮男人

    漂亮男人2017-06-30 09:59:59

    Because every time you call goBack, a new timer will be opened

    reply
    0
  • 天蓬老师

    天蓬老师2017-06-30 09:59:59

    A timer will be created when the first call returns. Another timer will be created when the timer call returns, and one will be closed at the same time. It seems that this process is always repeated, and there is always a timer. I don't understand what function you want to implement, but it will feel better if you take the code to create the timer outside the return method.

    reply
    0
  • 给我你的怀抱

    给我你的怀抱2017-06-30 09:59:59

    Put setInterval(this.goBack,50) outside this.goBack and call it

    reply
    0
  • Cancelreply