In our codebase, I keep coming across this pattern of invoking renderXelement() inside the render method. I have heard that it is not a very common pattern for React. Also, I was wondering whether is a thing to avoid at all costs, in a sense that what kind of downsides it has (if any).
See renderCollapsedLinks(). I removed some of the excessive code to make the question more clear.
Example:
export function NavigationDropdownLinksOverlay({
activeDropdownLink,
onClickBack,
}: NavigationDropdownLinkOverlay) {
const { classes } = useStyles();
const renderCollapsedLinks = (groupLink: DropdownGroupLinks) => {
return groupLink.links.map((link, index) => (
<Box mb={index !== groupLink.links.length - 1 ? 'sm' : 0}>
<Link href={link.link} className={classes.anchorLink}>
{link.label}
</Link>
</Box>
));
};
return (
<MobileNavigationOverlay show={!!activeDropdownLink}>
<MobileMenuBanner title={activeDropdownLink?.label || ''} />
<BackButton onClick={onClickBack} />
<Grid gutter={0} className={classes.linkGridFullWidth}>
{renderCollapsedLinks()}
</Grid>
</MobileNavigationOverlay>
);
}