Fork me on GitHub
#reagent
<
2022-01-04
>
3starblaze07:01:56

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.

p-himik07:01:20

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.

3starblaze08:01:27

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!

👍 1