删除反应中的项目(芯片标签)

时间:2020-09-21 16:47:43

标签: reactjs material-ui

嘿,我对react中的remove元素有疑问。单击删除按钮后,它不会被删除,它是一个芯片标签

这是我的代码:

import React, { useEffect, useState, Component } from 'react'
import Chip from '@material-ui/core/Chip'

const useStyles = makeStyles(theme => ({
  root: {
    display: 'flex'
  },
  chip: {
    backgroundColor: '#104d56'
  },
}))


   let handleDelete = (chipToDelete) => {


    setStudentlist(studentlist.filter((chip) => chip.key != chipToDelete))



  }


const studentlist = []

function ResponsiveDrawer(props) {
{
    namefamily.map((item, index) => {
      if (index + 1 > namefamily.length - gpcapacity) {
        if (showstu == item[2]) {
          studentlist.push(
            <Chip

              key={item[2]}
              className={classes.chip}
              clickable={false}
              variant="outlined"
              label={
                <Typography variant="caption" color="textSecondary">
                  {item[0]} {item[1]}
                </Typography>
              }
              onDelete={handele}
              icon={<FaceIcon />}
            />
          )
        } else
          studentlist.push(
            <Chip
              key={item[2]}
              variant="outlined"
              clickable={true}
              label={
                <Typography variant="caption" color="textSecondary">
                  {item[0]} {item[1]}
                </Typography>
              }

              icon={<FaceIcon />}
            />
          )
      }
    })
  }
}

,我有两个chip标签,

第一个是普通样式,第二个是当我将鼠标悬停在按钮上时,芯片的背景颜色将被更改。

当我按下删除按钮时,什么都没有改变

请帮助我

0 个答案:

没有答案