# Hold Evaluation in a MenuView or TabView

Suppose I wish to create a MenuView where the evaluation of the rules is time consuming.

How would I delay evaluation of the right-hand-side of the arguments to MenuView until that item is requested?

Here is a toy example that illustrates my question (it calls expensiveFunction on a set of matched items).

iList = RandomInteger[{1, 20}, {100, 2}];

getPairs[pairs_List] :=
With[
{cases = Echo@Cases[pairs, {a_, b_} /; (EvenQ[a] && EvenQ[b])]},
]

getPairs[iList]


The goal would be to Hold expensiveFunction[#2]& when the view is created, but release the hold when its label is requested. I've tried a few unsuccessful shots on goal with Hold and Attributes. Before going down the path of doing something with Dynamic, I was wondering if anyone with a better understanding of non-standard evaluation has a simpler solution.

You can delay evaluation with Dynamic:

#1 -> Dynamic[Pause[.1]; expensiveFunction[#2], SynchronousUpdating -> False] &


but you also need to set ImageSize->Automatic for MenuView, otherwise it will try to pre-render all Dynamics to determine appropriate ImageSize.

Full code:

getPairs[pairs_List] := With[
{cases = Echo@Cases[pairs, {a_, b_} /; (EvenQ[a] && EvenQ[b])]},