simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 1 | import { useMemo, forwardRef } from 'react'; |
Adrien Béraud | 88a5244 | 2021-04-26 12:11:41 -0400 | [diff] [blame] | 2 | import PropTypes from 'prop-types'; |
Adrien Béraud | ab519ff | 2022-05-03 15:34:48 -0400 | [diff] [blame] | 3 | import ListItem from '@mui/material/ListItem'; |
| 4 | import ListItemIcon from '@mui/material/ListItemIcon'; |
| 5 | import ListItemText from '@mui/material/ListItemText'; |
Adrien Béraud | 88a5244 | 2021-04-26 12:11:41 -0400 | [diff] [blame] | 6 | import { Link as RouterLink } from 'react-router-dom'; |
| 7 | |
| 8 | function ListItemLink(props) { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 9 | const { icon, primary, secondary, to, account } = props; |
Adrien Béraud | 88a5244 | 2021-04-26 12:11:41 -0400 | [diff] [blame] | 10 | |
| 11 | const renderLink = useMemo( |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 12 | () => |
| 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éraud | 88a5244 | 2021-04-26 12:11:41 -0400 | [diff] [blame] | 19 | |
| 20 | return ( |
| 21 | <ListItem button component={renderLink}> |
| 22 | {icon ? <ListItemIcon>{icon}</ListItemIcon> : null} |
| 23 | <ListItemText primary={primary} secondary={secondary} /> |
| 24 | </ListItem> |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 25 | ); |
Adrien Béraud | 88a5244 | 2021-04-26 12:11:41 -0400 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | ListItemLink.propTypes = { |
| 29 | icon: PropTypes.element, |
| 30 | primary: PropTypes.string.isRequired, |
| 31 | secondary: PropTypes.string, |
| 32 | to: PropTypes.string.isRequired, |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 33 | account: PropTypes.object, |
| 34 | }; |
Adrien Béraud | 88a5244 | 2021-04-26 12:11:41 -0400 | [diff] [blame] | 35 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 36 | export default ListItemLink; |