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 =
To_dom.of_textarea
@@ R.Html5.(
textarea ~a:[ a_id (Xml.W.return "input_area") ]
@@ React.S.map
(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" Dom_html.CoerceTo.select
|> Option.get
in
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.handler
s?
P.S. My reactive textarea looks verbose, and it doesn’t react on reactive events when I manually change the contents of text area, but it’s probably a topic for another question.