How, in Helix, to pass children from the props to the component itself?

i ran into trouble when using Helix with Slate. i believe my trouble is specific to Helix. my question is, how do i define a component that “passes the children through?” (forgive my bad terminology).

the React code i am using as basis is:

const CodeElement = props => {
  return (
    <pre {...props.attributes}>
      <code>{props.children}</code>
    </pre>
  )
}

my attempt to put it into CLJS with Helix is:

(defnc code-element [props]
  (d/pre (.-attributes props)
         (d/code (.-children props))))

i have little experience with Helix. but in Reagent hiccup, that final line would look something like (into [:code] (:children props).

i am hoping somebody with Helix experience could see this and spot some obvious flaw.

Indeed, props passed to your components defined with defnc are like maps and you get keys out of them using keywords.

Likewise, when passing dynamic props you use the & key which acts like the ... in JS.

(defnc code-element [props]
  (d/pre {& (:attributes props)}
         (d/code (:children props))))
1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.