The following messes with the onClick animation (the ListItem turns red):
<List>
<a href="https://www.google.com">
<ListItem button>
<ListItemText primary="Google" />
</ListItem>
</a>
</List>
While adding the link inside ListItem, only makes the transition work if ListItemText is clicked, which is not what I want. What is the correct way to add a link?
The easiest way to accomplish this is to make the
ListItem
a link by using thecomponent
prop:That way, the
ListItem
will be an anchor tag linking to the desired place, but still receive the appropriate styling so that there won't be any visual changes.The behavior of the
component
prop is documented here. Note that thehref
prop will be automatically passed to the anchor tag, as specified by the last line in the props documentation:to use with "react-router-dom"
the example is based in this section: docs