type action = | Tick; type state = { count: int, timerId: ref(option(Js.Global.intervalId)) }; let component = ReasonReact.reducerComponent("Counter"); let make = _children => { ...component, initialState: () => {count: 0, timerId: ref(None)}, reducer: (action, state) => switch (action) { | Tick => ReasonReact.Update({...state, count: state.count + 1}) }, didMount: self => { self.state.timerId := Some(Js.Global.setInterval(() => self.send(Tick), 1000)); }, willUnmount: self => { switch (self.state.timerId^) { | Some(id) => Js.Global.clearInterval(id) | None => () } }, render: ({ state }) => <div>{ReasonReact.string(string_of_int(state.count))}</div> };
Write once and run everywhere. Reason works on all the platforms you'll want to target: Android, iOS, Windows, Linux, Mac and even Web.
Rest easy without runtime errors in production. A powerful type system ensures that if the code compiles, it works!
Deeply integrated with React, JavaScript, and OCaml, Reason leverages the full power of these mature ecosystems.