Gleb Posobin 2020-08-15T05:46:51.367900Z

Is there a way to do server-side rendering for re-frame?

Marcus 2020-08-15T18:58:58.370800Z

Hi all! 🙂 I am new to clojurescript and reagent/re-frame. I have a problem with the following text input function. It renders nicely and state is updated but I get an error message from the browser: "A component is changing a controlled input of type text to be uncontrolled. Input elements should not switch from controlled to uncontrolled (or vice versa).". What have I missed? hmm..

(defn text [] [:input
               {:type "text"
                 :value @(rf/subscribe [:length])
                 :on-change #(rf/dispatch [:length-changed (-> % .-target .-value)])

Marcus 2020-08-15T19:08:37.371800Z

It seems the problem is related to the function being called multiple times or something.. runs fine higher up in the call stack

Marcus 2020-08-15T19:25:10.372500Z

before this code is called I have a cond function that only runs the text function in some cases.. not in the initial one

Marcus 2020-08-15T20:40:21.372900Z

and the error is only given on the first rendering. so I guess it is related to initial state

Marcus 2020-08-15T20:55:26.373300Z

indeed it seems related to the various form-x components.. need to read up on that

Gleb Posobin 2020-08-15T21:29:55.374Z

@marcus.akre This has to be a form-2 component ( I think, like this:

(defn text []
  (let [value (rf/subscribe [:length])
    (fn [] [:input
            {:type "text"
             :value @value
             :on-change #(rf/dispatch [:length-changed (-> % .-target .-value)])

Marcus 2020-08-15T21:47:17.375600Z

Yes. Thanks! 🙂 I just started reading about it. It seems to be the correct way.