Connectiving reactive event to event handler

I found a piece of code for dynamic creation of HTML5 elements and adding a reactive contents to it.

let open Js_of_ocaml_tyxml.Tyxml_js in
let input_area =
  @@ R.Html5.(
       textarea ~a:[ a_id (Xml.W.return "input_area") ]
            (fun n ->
              let n = n mod List.length examples in
              log "Got a signal with index %d" n;
              let _, spec = List.nth examples n in
              txt (Xml.W.return spec))
            (fst reactive_stuff123))

Also I know a piece of code to add a handler to already existing element using pure Js_of_ocaml:

let combo =
    Dom_html.getElementById_coerce "demos"
    |> Option.get
combo##.onchange := Dom_html.handler (fun _ -> (* stuff *)  Js._true);

Question: How could I use a reactive value as contents of already created HTML element? In other words, how should I combine reactive stuff with Dom_html.handlers?

P.S. My reactive textarea looks verbose, and it doesn’t react on reactive events :slight_smile: when I manually change the contents of text area, but it’s probably a topic for another question.

May I ask which lib you are using?

I use js_of_ocaml-tyxml which depends on React / Erratique

1 Like