Skip to content

Instantly share code, notes, and snippets.

@frekw
Created December 18, 2018 00:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frekw/2a6f5033f32f1bcfe179b248261cd205 to your computer and use it in GitHub Desktop.
Save frekw/2a6f5033f32f1bcfe179b248261cd205 to your computer and use it in GitHub Desktop.
type timerID;
[@bs.val] external setInterval: (unit => unit, int) => timerID = "setInterval";
[@bs.val] external clearInterval: timerID => unit = "clearInterval";
module Counter = {
let component = ReasonReact.component("Counter");
let make = (~initial = 0, _children) => {
...component,
render: _self => {
let (count, setCount) = ReactHooks.useState(initial);
ReactHooks.useEffectWithoutDependencies(() => {
setInterval(() => setCount(. count + 1), 1000) |> ignore;
None
});
<box width="50%" height="50%">
{ReasonReact.string({j|Count: $count|j})}
</box>
},
}
}
let screen = Blessed.screen(~smartCSR = true, ())
ReactBlessed.render(<Counter />, screen)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment