reagent

2023-03-22T15:00:09.382979Z

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}))

2023-03-23T09:43:49.247079Z

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.

juhoteperi 2023-03-23T09:58:01.165719Z

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.

2023-03-23T10:01:05.363209Z

Yeah, the problem for me with something like helix is that my ideal clojurescript world isn't just moving parenthesis and writing javascript in clojure.

2023-03-23T10:01:10.752349Z

I really like reagent's model based on atoms.

2023-03-23T10:01:22.712429Z

I don't know uix 2 so I will have to give it a look.

p-himik 2023-03-22T15:04:11.048709Z

Yes - React refs.

2023-03-22T15:09:05.442749Z

I tried adding a :ref field to that map (inside the with-meta call) but it didn't seem to work.

2023-03-22T15:09:22.444379Z

But I guess you may mean just doing that manually on each component instead of having a composable wrapper that arranges focus ?

2023-03-22T15:09:59.978469Z

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.

p-himik 2023-03-22T15:12:01.043689Z

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.

2023-03-22T15:13:13.701749Z

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.

p-himik 2023-03-22T15:13:23.224249Z

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).

2023-03-22T15:13:46.896009Z

Ah yes, but what I meant was that I do this:

2023-03-22T15:14:36.552539Z

Ah, sorry, you're right.

2023-03-22T15:14:43.200079Z

I can totally replace the case I was doing with that.

2023-03-22T15:14:44.859279Z

Thanks!

👍 1
juhoteperi 2023-03-22T15:21:26.471869Z

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.

juhoteperi 2023-03-22T15:22:37.984569Z

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