blob: d0205034ee72a9519e71be8a9ee2d637b165bbc1 [file] [log] [blame]
Adrien Béraudab519ff2022-05-03 15:34:48 -04001import ListItem from '@mui/material/ListItem';
2import ListItemIcon from '@mui/material/ListItemIcon';
3import ListItemText from '@mui/material/ListItemText';
simon07b4eb02022-09-29 17:50:26 -04004import PropTypes from 'prop-types';
5import { forwardRef, useMemo } from 'react';
Adrien Béraud88a52442021-04-26 12:11:41 -04006import { Link as RouterLink } from 'react-router-dom';
7
8function ListItemLink(props) {
simond47ef9e2022-09-28 22:24:28 -04009 const { icon, primary, secondary, to, account } = props;
Adrien Béraud88a52442021-04-26 12:11:41 -040010
11 const renderLink = useMemo(
simond47ef9e2022-09-28 22:24:28 -040012 () =>
13 forwardRef((itemProps, ref) => {
14 console.log('LIST ITEM LINK: ', account, itemProps);
15 return <RouterLink to={to} ref={ref} {...itemProps} state={account} />;
16 }),
17 [to]
18 );
Adrien Béraud88a52442021-04-26 12:11:41 -040019
20 return (
21 <ListItem button component={renderLink}>
22 {icon ? <ListItemIcon>{icon}</ListItemIcon> : null}
23 <ListItemText primary={primary} secondary={secondary} />
24 </ListItem>
simond47ef9e2022-09-28 22:24:28 -040025 );
Adrien Béraud88a52442021-04-26 12:11:41 -040026}
27
28ListItemLink.propTypes = {
29 icon: PropTypes.element,
30 primary: PropTypes.string.isRequired,
31 secondary: PropTypes.string,
32 to: PropTypes.string.isRequired,
simond47ef9e2022-09-28 22:24:28 -040033 account: PropTypes.object,
34};
Adrien Béraud88a52442021-04-26 12:11:41 -040035
simond47ef9e2022-09-28 22:24:28 -040036export default ListItemLink;