blob: 915a24ba287c32b69b0c41dcd520f91b5b9620ab [file] [log] [blame]
Adrien Béraud88a52442021-04-26 12:11:41 -04001import React, { useMemo, forwardRef } from 'react';
2import PropTypes from 'prop-types';
Adrien Béraudab519ff2022-05-03 15:34:48 -04003import ListItem from '@mui/material/ListItem';
4import ListItemIcon from '@mui/material/ListItemIcon';
5import ListItemText from '@mui/material/ListItemText';
Adrien Béraud88a52442021-04-26 12:11:41 -04006import { Link as RouterLink } from 'react-router-dom';
7
8function ListItemLink(props) {
9 const { icon, primary, secondary, to } = props
10
11 const renderLink = useMemo(
12 () => forwardRef((itemProps, ref) => <RouterLink to={to} ref={ref} {...itemProps} />),
13 [to])
14
15 return (
16 <ListItem button component={renderLink}>
17 {icon ? <ListItemIcon>{icon}</ListItemIcon> : null}
18 <ListItemText primary={primary} secondary={secondary} />
19 </ListItem>
20 )
21}
22
23ListItemLink.propTypes = {
24 icon: PropTypes.element,
25 primary: PropTypes.string.isRequired,
26 secondary: PropTypes.string,
27 to: PropTypes.string.isRequired,
28}
29
30export default ListItemLink