For my first React app I need to display a menu hiearchy with group-items, read-items and write-items (there are more, but that's enough for this example).
Each read-item and write-item are connected to a data point in a JSON API: each item has a resource (for example /api/1.0/fruits
) and a json-path (for example data.color
).
When the menu is displayed all values should be fetched from the web service. But I don't want each item to fetch its value independently because then the same resource would be read multiple times in the typical case.
I have a static, stateless menu structure as well that the views are built from. I can call a method, getRequiredResources()
, on the root menu item in this menu structure which will return a set of resources.
But then I've introduced dynamic menu items, so that depending on the state of the menu items different resources are required. I can no longer use the static menu structure to collect all required resources, since it has no knowledge about the state of each item.
Any hints on how to handle this? If I could access the child menu item components they hold enough state to return a list of required resources, but I don't think that's a recommended pattern...?
I use a Flux architecture for data flow.