How the composition of requests with unions works with the parent tree that passed through the props in Om Next

I have two components A and B. I want to switch between the two components on the page.

(defui A) (defui B) 

One solution is to use the parent component C:

 (defui C (render (let [{:keys [activeView]} props] (if (= activeView 'A') (renderA) (renderB))))) 

The problem is the request. C needs to be requested for both A and B, even if one of them is displayed.

I need C to not be included in the request or not request only A or B.

Is this true, or are there workarounds:

  • A child component can only request its details, which are transmitted by its parent.
  • The parent component must request its children in order to pass them on to the children.
  • Only the root component requests the app-state .
+5
source share
1 answer
  • A child component can only request its details, which are transmitted by its parent.

    • in your context, yes, that’s true. However, it can access top-level status keys using links. See this tutorial for more information.
  • The parent component must request its children in order to pass them on to the children.

    • Better, parent components combine their child queries into a root directory. The root component must have a full request for the application (this is what “root requests” means)
  • Only the root component requests the state of the application.

    • Not really. The root component will receive all the details and is responsible for passing them to subcomponents, but the request for the application state itself is performed in the read parser method.

I advise you to do all the tutorials in the Om Next Wiki to better understand how to do the right thing.

As for your specific problem, you can always make C implement IQueryParams and query the current subcomponent (either A or B) in the query parameter.

+2
source

Source: https://habr.com/ru/post/1237018/


All Articles