I have two components A and B. I want to switch between these two components on the page.
(defui A)
(defui B)
One solution is to use a parent component C:
(defui C
(render
(let [{:keys [activeView]} props]
(if (= activeView 'A')
(renderA)
(renderB)))))
The problem is query. C needs to query for both A and B, even though one of them gets displayed.
I need C to either not get involved in query, or query for either A or B only.
Are these true, or are there workarounds:
app-state
.A child component can only query its props, which is passed by its parent.
A parent component has to query for its children so that it can pass them to children.
Only the root component queries the app-state.
read
method.I advise you to do all the tutorials in the Om Next Wiki for better understanding how to do things properly.
Regarding your specific problem, you can always make C
implement IQueryParams
and have the current sub-component's (either A's or B's) query in a query parameter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With