I'm working on a table where clicking one icon changes all icons in the list to a different icon. However, I want to prevent them from changing simultaneously. Any suggestions on how to tackle this issue?
Code:
import React from 'react';
import {makeStyles, Theme} from '@material-ui/core/styles';
import Table from '@material-ui/core/Table';
import TableBody from '@material-ui/core/TableBody';
import TableCell from '@material-ui/core/TableCell';
import TableContainer from '@material-ui/core/TableContainer';
import TableHead from '@material-ui/core/TableHead';
import TablePagination from '@material-ui/core/TablePagination';
import TableRow from '@material-ui/core/TableRow';
import TableSortLabel from '@material-ui/core/TableSortLabel';
import IconButton from '@material-ui/core/IconButton';
import Tooltip from '@material-ui/core/Tooltip';
import FilterListIcon from '@material-ui/icons/FilterList';
import FavoriteBorderOutlinedIcon from '@material-ui/icons/FavoriteBorderOutlined';
import FavoriteOutlinedIcon from '@material-ui/icons/FavoriteOutlined';
...
export default function Table() {
...
const [isFavorite, setIsFavorite] = React.useState(false);
...
return (
...
return (
<TableRow
hover
tabIndex={-1}
key={row.name}>
<TableCell>{row.name}</TableCell>
...
<TableCell>
<IconButton onClick={() => setIsFavorite(!isFavorite)}>
{isFavorite ? <FavoriteOutlinedIcon color="secondary"/> : <FavoriteBorderOutlinedIcon color="action"/> }
</IconButton>
</TableCell>
...
);
}