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?
Asked
Active
Viewed 511 times
4
-
it seems, Reagent can reuse raw React components: https://github.com/reagent-project/reagent/blob/master/src/reagent/core.cljs#L46 – azaviruha May 11 '15 at 11:40
1 Answers
1
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.
![](../../users/profiles/611740.webp)
Chaos Rules
- 370
- 2
- 13
-
1Well, I don't have a problem to reuse *Om* component in Om app. The question is about reusing *React* components (writen in plain JavaScript React) in Om application. – azaviruha Feb 26 '15 at 04:47
-
I experimented with react when it first came out, so I took a look at my early code. And from the looks of it, I don't think there is any reason why I couldn't utilize it. After all, it is just JavaScript and Om compiles down to JavaScript. My current React Components, written in Om, utilize core.async and ref-cursors, so sharing data might be an issue. – Chaos Rules Feb 26 '15 at 18:16