As I'm only starting to fully understand, om.core/build
and om.next
's factory functions return React element objects, which refer to component functions/classes, and the actual component is only instantiated later by React's reconciler. That is, (om.core/build some-component data)
doesn't actually call some-component
immediately.
However, we often represent simple, "stateless" components as just functions which take props and return a React element. In the (pure) React world, you'd use one of these functions like a component class, as React.createElement(AStatelessComponent, {some: "props"})
, or more conveniently in JSX as <AStatelessComponent some="props" />
. Those too return a React element which references AStatelessComponent
, which won't actually be called until later.
But in Om, when we have a simple component like this (and by "we" I mean me and my team, at least), we call the function directly. Thus,
(render [this]
(om/div {}
(a-stateless-component {:some "data"})))
Here, a-stateless-component
is called immediately, and whatever it returns is inserted directly into the div, rather than being substituted later by the React reconciler.
Is there a preferred way to React.createElement
in Om? Or is it preferred to just call functions like this directly, even though it skips creating a component instance in the render tree?