rum

Simple, decomplected, isomorphic HTML UI library for Clojure and ClojureScript | 0.12.8 https://github.com/tonsky/rum/blob/gh-pages/CHANGELOG.md#0128
2020-05-25T04:50:11.127200Z

I've been trying to figure out how to do this in rum:

class MyComponent extends Component {
  componentDidMount() {
    this.node.scrollIntoView();
  }

  render() {
    return <div ref={node => this.node = node} />
  }
}
Anyone knows?

2020-05-25T04:51:24.127700Z

I just don't understand how I'm supposed to make use of ref

2020-05-25T05:14:09.130800Z

This is the best I got, is that the idiomatic rum way?

(rum/defcs MyComponent <
  {:class-properties {"node" (rum/create-ref)}
   :did-mount
   (fn[state]
     (.scrollIntoView (.-node (:rum/react-component state)))
     state)}
  [state]
  [:div {:ref (.-node (:rum/react-component state))}])

2020-05-25T07:22:56.132900Z

(rum/defc MyComponent []
  (let [ref (rum/use-ref nil)]
    (rum/use-effect! #(.scrollIntoView (rum/deref ref))
                     [])
    [:div {:ref ref}]))

2020-05-25T07:23:24.133500Z

the above should work with hooks

2020-05-25T10:39:58.134800Z

Hum, I'd need to switch fully to hooks though for that. Is what I did for class based components the best it gets?

2020-05-25T10:43:09.135200Z

Not fully, just for that component by using defc

2020-05-25T10:51:43.136600Z

Hum, that's true, I could explore that option, though I think I might be using other mixins. But I guess I can learn hooks and move those to hooks as well

2020-05-25T17:19:41.136700Z

@didibus Untested

levitanong 2020-05-26T18:43:20.137300Z

did-mount would probably need to return rum-state.

(fn [state] 
  (.scrollIntoView (rum/dom-node state))
  state)

2020-05-26T19:24:35.137500Z

dom-node is deprecated though. I was trying to use the suggested replacement. Which based on the react documentation, is what I pasted above, that is to use a ref