0

In my react project I need to use setInterval(), but instead of repeatedly launching is launch only one time. (Pseudo code below) . Does anyone know how fix this? In other stackoverflow questions I doesn't find what I need.

/*---- React Component ----*/
class Grid extends Component {
  componentDidMount() {
    setInterval(timeline.launch(), 1000);
  }

  render() {
    return (
      <GridView />
    )
  }
}

/*---- Timeline Function ----*/

const $ = window.$;

class lifeTimeline {
  launch() {
    $(document).ready(function() { /* Render Timer on the screen */ }
      
  }
}

const instance = new lifeTimeline();
export default instance;
mplungjan
  • 169,008
  • 28
  • 173
  • 236
Rami Chasygov
  • 2,714
  • 7
  • 25
  • 37
  • 2
    Javascript issue: unless timeline.launch() returns a function, you want `setInterval(timeline.launch, 1000);` and more likely `setInterval(instance.launch, 1000);` but then again you would not want each second add an onload handler after onload: `$(document).ready(function() { /* Render Timer on the screen */ }` – mplungjan Jan 13 '18 at 08:21
  • 1
    "_In other stackoverflow questions I doesn't find what I need_" [No?](https://stackoverflow.com/questions/24542207/setinterval-fires-only-once) – Teemu Jan 13 '18 at 08:24
  • @Teemu, )) I searched with other keywords – Rami Chasygov Jan 13 '18 at 08:26
  • @mplungjan, then what I should do ? Is it possible somehow set if statement – Rami Chasygov Jan 13 '18 at 08:27
  • 1
    componentDidMount is enough. Just insert the timer value in launch – mplungjan Jan 13 '18 at 08:32
  • Your search case implements very well, how useful it is to write "_it doesn't work_" to a post. Please get rid of it, and describe the real problem instead in the title too. – Teemu Jan 13 '18 at 08:35

1 Answers1

-1

setInterval requires a function object, but you are calling launch. move setInterval inside launch, and then you can call launch inside componentDidMount