From the Elmish docs:
open Elmish
open Fable.Core
let timer initial =
let sub dispatch =
JS.setInterval
(fun _ ->
dispatch (Tick DateTime.Now)
)
1000
|> ignore
Cmd.ofSub sub
Program.mkSimple init update (fun model _ -> printf "%A\n" model)
|> Program.withSubscription timer
|> Program.run
If this were part of a more complex app, it would be good for the setInterval
to be cancelled if the component is unmounted.
With React hooks, this is part of the component life-cycle.
I am wondering how this works in Elmish?