Fork me on GitHub

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 . Thanks for the help!

👍 1