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
Karol W贸jcik 2020-07-15T08:39:18.171700Z

How to mix react higher order component with rum?

2020-07-15T09:22:25.172300Z

@karol.wojcik could you post an example?

Karol W贸jcik 2020-07-17T13:57:42.192100Z

Thank you very much @roman01la

馃檹 1
Karol W贸jcik 2020-07-15T09:25:37.174Z

Supposing I got the following function:

(ns css-cljs.shared
  (:require
   [cljs-bean.core :refer [->js]]
   [react-jss :as rcs]))

(defn with-styles
  ([styles]
   (with-styles styles {}))
  ([styles opts]
   (rcs/withStyles (->js styles) (->js opts))))
which using that library https://cssinjs.org/react-jss?v=v10.3.0 Now what I would like to achieve is to wrap the Rum component with Reagent HOC
(ns css-cljs.rum
  (:require
   [css-cljs.shared :as csh]
   [rum.core :as rum]))

(def styles (rum/adapt-class (csh/with-styles {:div {:font-weight "bold"}})))

(rum/defc View
  []
  [:div {} "Hello"])

(rum/mount (styles View) (js/document.getElementById "root"))

Karol W贸jcik 2020-07-15T09:26:56.174300Z

In reagent it was fairly simple:

(ns css-cljs.reagent
  (:require
   [cljs-bean.core :refer [bean]]
   [reagent.core :as r]
   [css-cljs.shared :as csh]))

(defn- NormalizeStylesheetWrapper
  [component]
  (fn [& args]
    (as-> (first args) opts
      (apply component
             (merge opts {:classes (bean (:classes opts))})
             (rest args)))))

(defn with-styles
  [& args]
  (fn [component]
    (r/adapt-react-class
     ((apply csh/with-styles args)
      (r/reactify-component (NormalizeStylesheetWrapper component))))))

2020-07-15T09:42:33.174500Z

I see, thought there's a guide or an example for this in the repo already

2020-07-15T09:55:58.174700Z

So since Rum component is a function that takes any number of args, you'd have to wrap it into a function that takes React's js props object and passes what's needed into Rum componnet

2020-07-15T09:57:15.174900Z

(rum/defc f [a b c] ...)

(defn f-react [^js props]
  (f (.-a props) (.-b props) (.-c props)))

2020-07-15T09:57:55.175100Z

in this example f-react is a React component that acts as interop layer between React and Rum

Karol W贸jcik 2020-07-15T12:30:37.175800Z

@roman01la got something like:

#js {$$typeof #object[Symbol(react.forward_ref)], :render #object[Function], :displayName JssContextSubscriber(Component), :InnerComponent #object[Function]}
How to transform it to React component?

2020-07-15T14:10:40.176200Z

that's an instance of react component

2020-07-15T14:11:15.176400Z

put it as a child into a receiving component

Karol W贸jcik 2020-07-15T20:12:50.185600Z

Could you please show the example? I don't follow

Karol W贸jcik 2020-07-15T20:24:35.185800Z

Ok I think I've figured it out.

(js/React.createElement here-the-thing-ive-posted #js {} nil)