Material Table 内部 onClick 仅显示最后一行值

Material Table inner onClick shows only last row value

所以我遇到的问题是我有一个自定义呈现的列,里面有一个菜单按钮,单击它会打开这样的菜单:

现在看下面的代码:

  columns={[
                    {
                        title: 'Actions',
                        field: 'tableData.id',
                        render: rowData => {
                            return (
                                <div>
                                    <IconButton aria-controls="simple-menu" aria-haspopup="true" onClick={handleClick}>
                                        <MenuIcon />
                                    </IconButton>
                                    <Menu
                                        className={classes.menu}
                                        id="simple-menu"
                                        anchorEl={anchorEl}
                                        keepMounted
                                        open={Boolean(anchorEl)}
                                        onClose={handleClose}
                                    >
                                        <MenuItem className={classes.sendMail} onClick={()=> 
                                                                 {console.log(rowData)}}>
                                            <ListItemIcon className={classes.icon}>
                                                <SendIcon fontSize="default" />
                                            </ListItemIcon>
                                            Send Assessment Email
                                        </MenuItem>
                                    
                                    </Menu>
                                </div>
                            )
                        },
                    },

来自行的值,即 rowData 在 IconButton 组件的第一个 onClick 上很好,但 MenuItem 的第二个 onClick 仅显示最后一个 rowData 值,无论我在哪一行 select。 任何帮助,将不胜感激。谢谢。

编辑:我通过在 useState 内的 Menubutton 上设置 selected 行来部署快速修复,然后将该值用于其他操作,但我想知道这是本机的还是我应该说可能默认而不是我采取的方法。我尝试停止事件传播但徒劳无功。

感谢您提出这个问题,并看到我并不孤单...

我不确定这是否可以作为解决方案或解决方法,但它对我有用。

  1. On the button being used to open the menu, I use the onClick event to set the selected menu row which I want to use, and save it to the component state.
    const [slcRow, setSlcRow] = React.useState(null);
    const handleClick = (event, row) => {
        setAnchorEl(event.currentTarget);
        setSlcRow(row);
    };

    <Button 
        aria-controls="simple-menu" 
        aria-haspopup="true" 
        onClick={(event ) => {handleClick(event, row) }}
        >
        Open Menu
    </Button>
  1. In the MenuItem onClick event I check the state to retrieve that row and do the work needed...
   const handleEditOpen = (event) => {
       let row = slcRow;
       loadEditData(row.clientId);
       setEdit(true);
       setAnchorEl(null);
   };

   <Menu id="long-menu" anchorEl={anchorEl} keepMounted open={open} onClose={handleClose1}>
       <MenuItem onClick={(event) => { handleEditOpen(event) }}>Edit </MenuItem>
   </Menu