This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-01-04
Channels
- # aleph (1)
- # asami (6)
- # babashka (44)
- # beginners (20)
- # calva (6)
- # circleci (1)
- # clj-kondo (2)
- # cljdoc (2)
- # clojure (184)
- # clojure-europe (13)
- # clojure-nl (4)
- # clojure-spain (1)
- # clojure-uk (4)
- # clojurescript (35)
- # code-reviews (1)
- # conjure (3)
- # core-async (60)
- # core-logic (1)
- # cursive (11)
- # data-science (2)
- # events (11)
- # graalvm (4)
- # graphql (2)
- # introduce-yourself (1)
- # jobs (2)
- # leiningen (3)
- # malli (16)
- # minecraft (6)
- # practicalli (1)
- # reagent (3)
- # reitit (1)
- # releases (3)
- # remote-jobs (2)
- # rewrite-clj (21)
- # shadow-cljs (12)
- # tools-deps (21)
- # vim (16)
Hello there, I'd appreciate help on this issue: How to obtain an HTML property from a reagent object?
For context, I'm making a component that has a side menu that slides from the right to the left. To make that sliding perfect, I need to get the width of the element (via .-offsetWidth
). I don't know how to retrieve a reference to HTML element to read this value.
I am using reagent.core/create-class
and :component-did-mount (fn [this] ,,,)
but this
is not an HTML element but a reagent object. I'm not sure how can I get HTML element and extract .-offsetWidth
from it.
I've stumbled upon React's refs but that doesn't seem to address the problem of how I'd get the component itself.
Use React refs. It's very well documented. I'd start with React documentation on refs in general and then switch to Reagent documentation to learn how to use refs in Reagent.
You might see some examples that use react-dom
to get the DOM node from this
but don't use it - it's a deprecated method.
I read about refs more carefully and I managed to solve the problem using this example https://cljdoc.org/d/reagent/reagent/1.1.0/doc/frequently-asked-questions/how-do-i-use-react-s-refs- . Thanks for the help!