This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-11-09
Channels
- # announcements (14)
- # architecture (42)
- # babashka (23)
- # beginners (37)
- # biff (8)
- # calva (2)
- # cider (3)
- # clara (42)
- # clerk (14)
- # clojure (55)
- # clojure-brasil (3)
- # clojure-dev (5)
- # clojure-europe (18)
- # clojure-hungary (88)
- # clojure-losangeles (3)
- # clojure-nl (1)
- # clojure-norway (66)
- # clojure-uk (9)
- # clojurescript (16)
- # core-logic (16)
- # datomic (6)
- # fulcro (32)
- # hyperfiddle (25)
- # instaparse (12)
- # joyride (2)
- # lsp (13)
- # malli (15)
- # off-topic (50)
- # polylith (11)
- # portal (3)
- # re-frame (2)
- # reitit (2)
- # sci (8)
- # shadow-cljs (16)
- # tools-deps (13)
- # xtdb (5)
in a form/defsc is it possible to setup a hook that uses the this
?
I tried that:
(hooks/use-effect (fn []
(app/register-push-handler :new-topic
(fn [message]
(log/info this)
(log/info (comp/get-ident this))
(log/info (comp/props this))
(form/input-changed! {::form/instance this}
:topic/description "banana")))
(fn []
(app/deregister-push-handler :new-topic)))
[])
but comp/props is failing
my intention is to have a chatbot stream inputs into the form via websocketDefinitely do not do it this way. In my opinion you should never set up side effects in the UI if you can avoid it, and in this case you're trying to close over a thing that is mutable in react. In general, hooks are great for some things, but this is not one of them. What you want to do is register a function and pass it the ident of the UI component that you want to update. Then all you have to do is run mutations that update the data in app State at that ident, and the UI will follow along.
I mean, you can use the hook to do the registering... But just grab the ident to begin with, so that you have a constant value to form the closure with
Yeah I didn’t really want to use ‘this’ but that was what ‘input-changed’ needed
I ended up using trigger directly as the params are not that hard to build up
I’m actuall kind of surprised the props function didn’t work. I mean it is working on a mutable js object that React owns, but I would not have expected it to change.
The dynamic vars will be out of context in the async callback, but props doesn’t require those.
Perhaps it is one of these: https://react.dev/reference/react/useEffect#caveats
When Strict Mode is on, React will run one extra development-only setup+cleanup cycle before the first real setup. This is a stress-test that ensures that your cleanup logic "mirrors" your setup logic and that it stops or undoes whatever the setup is doing. If this causes a problem, implement the cleanup function.
none of their examples show using this
within the effect. Instead if there is something in the props needed by the effect it is first destructured and included in the dependencies.
So I expect it is something you’re doing wrong or that the effect system of React is being weird about. but in general this
should be usable in functions…how else would onClick
work and allow the use of this
Technically having “no deps” in the data dependency list seems a bit off, given that if you want something from props you clearly have a dependency?
My understanding is that you make a useEffect with no dependencies when you want it to run on mount and unmount only
I though I was capturing the scope
React has gotten weirder and weirder internally as they’ve added hooks and async stuff. I would not bet on things like order of operations.
I put that in the indexes as well and it always seems to work. So, I can’t really tell you why it wouldn’t, other than Fulcro isn’t “in charge” of these React details.
my guess would be that on-mount "this" is not looking enough like an instance of form for comp/props?
actually this works
(hooks/use-effect (fn []
(log/info :props (comp/props this))
(fn []
(app/deregister-push-handler :bitch)))
[])
I guess what I was doing was just too illegal 😄
I find it rather curious. Off the top of my head I can’t really say why it wouldn’t work other than timing.
ok it's not the props, I made a simpler example (let [_ (hooks/use-effect (fn [] (reset! a (fn [] (form/input-changed! this :subject/description "hello"))) (fn [])) [])] (dom/div :.my-container (dom/button {:onClick #(@a)} (dom/label "DANGER")) getting the same issue but I can log the props the error happens after it was the wrong line
@U0CKQ19AQ ok it had nothing to do with react: this works:
(let [_ (hooks/use-effect (fn []
(reset! a (fn []
(js/alert (comp/get-ident this))
(form/input-changed! {::form/form-instance this
::form/master-form this} :subject/description "hello")))
(fn []))
[])]
(dom/div :.my-container
(dom/button {:onClick #(@a)} (dom/label "DANGER"))
I was passing this
it was expecting an env
Fulcro RAD question: Has anyone used fo/field-visible?
or fo/fields-visible?
on blob attributes? I cannot make it work.
It is entirely possible that I have not implemented all of the aspects on blob rendering. Check the sui plug-in code.
Sorry, still learning... So basically the only thing missing is the rendering conditional that queries for the visibility when rendering the attribute field? As I plan to write my custom form rendering that should be easy to implement. Maybe I can be of use and provide a pull request for the sui plug-in but as I have a narrow timeline I cannot promise it.