You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Had we stuck to elements, we could have done this:
<Menu><MenuItemclassName="bg-white"onSelect={download}><DownloadIcon/> Download
</MenuItem><MenuItemclassName="bg-white"onSelect={save}><SaveIcon/> Save
</MenuItem><MenuItemclassName="bg-white"onSelect={preview}aria-label="Preview Invoice"><PreviewIcon/> Preview
</MenuItem></Menu>
But how will the MenuItem components know their index?
In this situation, couldn't the MenuItem component just receive it's index since we know it at declaration time? That is:
<Menu><MenuItemindex={0}className="bg-white"onSelect={download}><DownloadIcon/> Download
</MenuItem><MenuItemindex={1}className="bg-white"onSelect={save}><SaveIcon/> Save
</MenuItem><MenuItemindex={2}className="bg-white"onSelect={preview}aria-label="Preview Invoice"><PreviewIcon/> Preview
</MenuItem></Menu>
I can see where this would be an issue if something were to be dynamic, but in the case of composite widgets, I don't foresee a situation in which a descendant would render conditionally. I am curious to hear about why this approach might not be optimal.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I was reading the
@reach/descendants
package README and came across this snippet:In this situation, couldn't the
MenuItem
component just receive it's index since we know it at declaration time? That is:I can see where this would be an issue if something were to be dynamic, but in the case of composite widgets, I don't foresee a situation in which a descendant would render conditionally. I am curious to hear about why this approach might not be optimal.
Beta Was this translation helpful? Give feedback.
All reactions