This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-03-22
Channels
- # alda (2)
- # announcements (1)
- # babashka (32)
- # beginners (67)
- # calva (1)
- # cider (19)
- # clerk (11)
- # clj-commons (35)
- # clj-kondo (7)
- # cljsrn (2)
- # clojure (35)
- # clojure-europe (86)
- # clojure-nl (5)
- # clojure-norway (5)
- # clojure-russia (6)
- # clojurescript (16)
- # clr (21)
- # conjure (1)
- # core-async (10)
- # cryogen (1)
- # cursive (12)
- # data-science (1)
- # emacs (29)
- # events (4)
- # figwheel-main (2)
- # graalvm (9)
- # gratitude (7)
- # honeysql (4)
- # hugsql (3)
- # hyperfiddle (23)
- # jobs (1)
- # jobs-discuss (4)
- # joyride (9)
- # malli (2)
- # off-topic (81)
- # portal (7)
- # reagent (19)
- # reitit (1)
- # releases (4)
- # shadow-cljs (121)
- # xtdb (3)
Is there way to do something like this without using the now-deprecated dom-node
call?
(defn set-focus
[this]
(.focus (d/dom-node this)))
(def focus-wrapper
"Pass-through component which ensures its argument receives focus when mounted."
(with-meta identity
{:component-did-mount set-focus}))
I tried adding a :ref
field to that map (inside the with-meta call) but it didn't seem to work.
But I guess you may mean just doing that manually on each component instead of having a composable wrapper that arranges focus ?
The thing is, this wrapper works with random bits of hiccup if you want - which I don't I think I can just add a ref field to ? Or maybe I can, I dunno.
Yeah, AFAIK you can't have such a wrapper in React without using that deprecated call that will eventually be (or maybe already is in 18) removed.
Ok, thank you for the help - I am sure I probably don't fundamentally need this, but it's funny when something gets deprecated that no one quite knows how to replace directly.
Also if you know in advance which components will use that wrapper, it can be replaced with just one line passed to a node's attribute map: :ref #(some-> ^js % .focus)
.
Class components never properly solved how to create reusable "mixins"/utilities. Your wrapper doesn't e.g. work if multiple wrappers define component-did-mount
.
React Hooks solve this, though the way to use them is a bit different.
Focusing input is so simple you can do that with ref
fn directly, but you can check e.g. https://github.com/streamich/react-use for examples of reusable util hooks
I like the concept of hooks, but reagent still has some subtle problems using hooks, as far as I can tell. Once we start using hooks, you can start to get periodic (spurious, as far as I can tell) errors about leaks and stuff like that in development mode during code reloading.
Helix and Uix 2 are good choices to build apps using Hooks. But I have several Reagent apps on production using some hooks without problems.