When using ClojureScript with a React library beware that the
:value for an
:input needs to be of type string. If this is not the case then screen updates initiated from the code sometimes fail.
Demonstration of the issue
I’ve used Rum for a demonstration of the issue –not suggesting that this is Rum specific (haven’t tried this with other ClojureScript React libraries).
If one takes the correct Rum examples code, in which the type is correctly converted to a string via a
(str value), as shown below:
And change this correct code, omitting the
(str ..), as follows:
And do a
lein cljsbuild once to compile the code and then load the index.html file in the browser.
Then the text field is not always updated when its value is set in the ClojureScript code. In the Rum example this is when –in the inputs box– clecking a checkbox, clicking a radio button, selecting a dropdown element, clicking the Next value button.
Note in the
Inputs box (first colum, middle row) the value for
Input (which is
1) and the
value (which indicate
Normally (with the
(str value) in place) these inputs would always be synchronized and show the same value.
Older React versions
This update issue appears not to occur with older React versions, for example:
But it does occur with the latest versions (e.g. Rum 0.11.2 and React 16.3.0-1).