levand / quiescent

A lightweight ClojureScript abstraction over ReactJS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

question about composition

roti opened this issue · comments

Hi,

Is there a way for a parent component to change the behaviour of their children (i.e. change the rendering output of the children)?

I am looking to solve following problem: a layout component needs information from their children in order to do it's job, namely it needs to insert some css into the dom generated by the child components.

For example, for the layout component below, I want to add the css style "flex-grow: " to those children, where the state contains a value :weight.

(def Layout
  (q/component
    (fn [{:keys [direction]} & content]
      (apply d/div
             {:style {:display "flex"
                      :flex-direction (case direction
                                        :vertical "column"
                                        :horizontal "row")}}
             content)
      )))

There's no built-in way to control how children render without editing the renderers for the children themselves.

You could, I suppose, write some functions mutate the react Elements (in this case the content you pass in) before returning them. That will be orthagonal to the capabilities that Quiescent provides, however.