blob: a0ebc3b4e1539e4394d4f738f22af1513f1cd1a7 [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) {
ervinanoh99655642022-09-01 15:11:31 -04009 const { icon, primary, secondary, to, account } = props
Adrien Béraud88a52442021-04-26 12:11:41 -040010
11 const renderLink = useMemo(
ervinanoh99655642022-09-01 15:11:31 -040012 () => forwardRef((itemProps, ref) => {
13 console.log("LIST ITEM LINK: ", account, itemProps)
14 return <RouterLink to={to} ref={ref} {...itemProps} state={account}/>}),
Adrien Béraud88a52442021-04-26 12:11:41 -040015 [to])
16
17 return (
18 <ListItem button component={renderLink}>
19 {icon ? <ListItemIcon>{icon}</ListItemIcon> : null}
20 <ListItemText primary={primary} secondary={secondary} />
21 </ListItem>
22 )
23}
24
25ListItemLink.propTypes = {
26 icon: PropTypes.element,
27 primary: PropTypes.string.isRequired,
28 secondary: PropTypes.string,
29 to: PropTypes.string.isRequired,
ervinanoh99655642022-09-01 15:11:31 -040030 account: PropTypes.object
Adrien Béraud88a52442021-04-26 12:11:41 -040031}
32
33export default ListItemLink