azaviruha
azaviruha

Reputation: 897

Is it possible to reuse existing React components in ClojureScript Om app?

I have a lot of React components in my current project. Is it any way to reuse this components, if I decide to write next project in Om?

Upvotes: 4

Views: 529

Answers (1)

Chaos Rules
Chaos Rules

Reputation: 520

Yes, it is possible. I created a Date Component that I have four instances of. One is for selecting a Day and another is for selecting a Week.

So, when I create them, I pass in a map to configure them:

(om/build common/column-input-date {:component-id :selected-daily-date})
(om/build common/column-input-date {:component-id :selected-weekly-date})
(om/build common/column-input-date {:component-id :selected-monthly-date})
(om/build common/column-input-date {:component-id :selected-jobs-date})

Then in the component:

(defn column-input-date [data owner]
  "column input date"
    (reify
      om/IInitState
      (init-state [_]
                  {:e-map {:display (:display data)
                           :component-id (:component-id data)}})
      om/IDidMount

Beyond, the page, everything is a component, so I have about 20 components. Mine communicate via core.async and get their data from ref-cursors. I tried passing data down the component tree and decided that was over-coupled.

Upvotes: 1

Related Questions