This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-07-10
Channels
- # beginners (15)
- # boot (15)
- # cider (6)
- # cljs-dev (231)
- # cljsjs (1)
- # cljsrn (26)
- # clojure (147)
- # clojure-argentina (1)
- # clojure-dev (8)
- # clojure-germany (1)
- # clojure-italy (26)
- # clojure-russia (2)
- # clojure-spec (83)
- # clojure-uk (154)
- # clojurescript (123)
- # conf-proposals (3)
- # core-async (5)
- # cursive (26)
- # datascript (21)
- # datomic (120)
- # emacs (2)
- # graphql (9)
- # hoplon (195)
- # instaparse (16)
- # jobs-discuss (1)
- # leiningen (8)
- # luminus (8)
- # lumo (7)
- # off-topic (17)
- # om (7)
- # om-next (3)
- # parinfer (121)
- # pedestal (5)
- # planck (13)
- # re-frame (11)
- # reagent (21)
- # ring-swagger (2)
- # spacemacs (28)
- # uncomplicate (3)
- # unrepl (7)
- # untangled (34)
- # vim (5)
I have a piece of code where:
[(fn []
[:input {:size "80"
:value @r-text
:on-change #(reset! r-text (ba.js/value-<-event %))}])]
causes the input field tol lose focus whenever I click on it
yet
[:input {:size "80"
:value @r-text
:on-change #(reset! r-text (ba.js/value-<-event %))}]
works perfectly fine.
This is confusing to me, as I generally expect that adding a [(fn [] .... )] should never cause something to not work (as it just "adds a layer of redirection causing the part to re-rendr when an r-atom it uses chanves value).right, but wouldn’t it be strange for an item that gets deleted and recreated to preserve focus status?
@qqq have you tried giving react a hint that you are updating a component with :key
metadata or attr ?
@qqq, the problem could be that the component gets unmounted and remounted again in the first example
it's one of these corner cases ("stateful" components) where keeping a component mounted is necessary, not just for performance but also for user experience
I think this is what @mccraigmccraig is suggesting as well?
I'd first verify that this is the problem by adding logging to the component (make it a form-3 component and add did-mount and will-unmount lifecycle methods that log)
yes @pesterhazy that is what i was meaning
the other possibility is that is matters where you are dereffing the ratom
so the issue might be todo with the surrounding code - something else higher up in the comp tree gets rerendered, causing the remount
@mccraigmccraig @pesterhazy : resolved the issue ; in the end
[(fn [] ....)] // loses focus on click
(def some-component (fn [] ...))
[some-component] // works
so it appears to be due to "the vector containing a fn created on the fly makes bad thingshappen"It makes sense because the Anon fn gets created on every render
It's a new object reference each time
So react assumes that it's seeing a different comp
Substitution is not broken because you're dealing with the function as an object reference, not with a simple call. Philosophically speaking the function is mentioned, not used
@pesterhazy : thanks for clarying this