This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-10-05
Channels
- # 100-days-of-code (13)
- # announcements (3)
- # beginners (120)
- # boot (17)
- # calva (19)
- # cider (27)
- # cljdoc (3)
- # cljs-dev (1)
- # clojure (138)
- # clojure-dev (5)
- # clojure-italy (5)
- # clojure-nl (20)
- # clojure-russia (3)
- # clojure-spec (14)
- # clojure-uk (119)
- # clojurescript (45)
- # core-async (2)
- # datomic (23)
- # editors (28)
- # emacs (35)
- # figwheel (2)
- # fulcro (26)
- # graphql (2)
- # hyperfiddle (11)
- # jobs (4)
- # luminus (5)
- # mount (2)
- # off-topic (52)
- # onyx (39)
- # reagent (86)
- # ring-swagger (2)
- # spacemacs (20)
- # tools-deps (9)
- # yada (4)
(def users (r/atom nil))
(defn set-users! [user-data]
(swap! users user-data))
(defn get-users []
(GET "/users" {:handler set-users!
:format json}))
(defn user-table []
(get-users)
(fn []
[:table [:tr [:th "first"][:th "last"]]
(map make-row @users)]))
I had a loop before I changed from the returning a component to returning a function
my guess without seeing the real code is that a parent of user-table
also depends on users
so you’re causing a loop of some kind
unlikely. but easy enough to just restart everything and refresh the browser. i’m just speculating but i don’t really understand why you think it’s broken
Hi! Does anybody know in reagent/re-frame I can touch the original, JS-component to update its state? I’m developing a React Native app with re-natal. The problem is, I need to update a state of a picker UI widget. Here is how they do that in vanilla JS: https://stackoverflow.com/questions/37597665/how-to-make-react-native-picker-stay-at-newly-selected-option My problem is, I cannot see an option to do that in re-frame. Keeping a state in 2nd form component leads to the whole widget re-renders ugly.
@igrishaev there are docs on this https://github.com/Day8/re-frame/blob/master/docs/Using-Stateful-JS-Components.md
There's more to the recipe than using a Form3
Well, it won’t work unfortunately. The problem is, I need to update the component’s state directly.
You cant circumvent react iirc
Uses a virtual dom as an intermediate if im not mistaken
what's the best way to apply a transformation to a ratom for consumers? e.g.
(let [v (r/atom 0)]
;; applies `inc` to the value of v before returning it; will update anytime v changes
@(rmap v inc))
what's rmap?
(swap! v inc)
quick readable intro: https://reagent-project.github.io/
transforming it how?
incrementing by one?
yeah that's actually (swap! v inc), it's called swap because its replaced by a new one, which is the result of (f x)
(rmap v inc)
returns a ratom who's value is inc
applied to the value of the ratom v
to change the value you'd use (reset! v 3)
oh a new atom?
sorry im confused haha
interesting
@coinedtalk what I want to do is take an original ratom with some state, and create a new ratom that will update anytime the original one does, but applies some transformation to the value of the original
(let [a (r/atom 0)
b (rmap a inc)]
[:div [:span @a] [:span @b]])
=> [:div [:span 0] [:span 1]]
I'm looking at make-reaction and track now in the documentation
@igrishaev I’m not 100% sure about what you are doing, but looking at that post I don’t think there is any reason why you need to store the state of the picker using react’s internal state mechanism in the first place. Just store the state in a ratom, set the selectedValue
using the dereffed ratom (instead of using this.state.pickerValue
), and then update the ratom using the onValueChange
event handler.
@lee.justin.m the r/atom solution leads to unwanted behavior when a picker start trembling. See how they do that in js: https://stackoverflow.com/questions/37597665/how-to-make-react-native-picker-stay-at-newly-selected-option
oh you know this may be an issue with async rendering and input events. though I really don’t know how that works with native.
the idea is how to change the state of a component that is behind the reagent wrapper
the post you shared, though, looks like a normal bug to me: the OP just used the wrong state value
right, with normal web stuff, reagent special cases things like input
events because you must change them synchronously
I believe you can just call current-component
and get the underlying react component. from there you can just use js interop to access setState
well, I tried to capture a reference to the js-component. but calling (.setState)
on it didn’t make any result.
my last hope is to rewrite it with the 3rd form redefining :should-component-update
maybe
if the issue is a flicker or some kind of async weirdness, I think you’re going to have to get access to the react component and update the underlying value synchronously when the onValueChange
event rolls in. at least this is often the issue with input elements in the dom