Excluir chip em react js Material-ui
Sep 20 2020
Eu trabalhei com react-js e material-ui chip. Eu adicionei muitos chips e então um chip apareceu com o texto. Desejo ter a funcionalidade de excluir o chip. mas não consigo como excluí-lo.
como posso excluí-lo onDelete={}?
aqui está apenas parte do meu código:
import React, { useEffect, useState, Component } from 'react'
import Chip from '@material-ui/core/Chip'
const useStyles = makeStyles(theme => ({
root: {
display: 'flex'
},
chip: {
backgroundColor: '#104d56'
},
}))
const handleDelete = () => {
console.log(hashtag);
};
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 />}
/>
)
}
})
}
}
o que vai estar dentro da handleDelete()função?
Respostas
1 PrasadPhule Sep 20 2020 at 19:15
De acordo com meu entendimento
namefamilyé uma matriz de matriz, ou seja[['a','b','c'],['x','y','z']]- você quer pular algumas fichas de estudante usando a
if (index + 1 > namefamily.length - gpcapacity) {condição - permitir deletar fichas para o
showstualuno usandoshowstu == item[2]condição
Resp: Você ResponsiveDrawerparece
veja meu comentário no código para mais detalhes.
const ResponsiveDrawer = () => {
//considering you are getting showstu and gpcapacity as props or from somewhere
const classes = useStyles();
// point 2. you can skip here instead of checking if everytime
const [chipData, setChipData] = React.useState(
namefamily.slice(0, ((namefamily.length - 2) - gpcapacity))
);
const handleDelete = (chipToDelete) => {
setChipData((chips) => chips.filter((chip) => chip[2] !== chipToDelete));
};
return (
chipData.map((item, index) => {
let chipProps = { clickable:true };
//point 3. allowing delete to those who is {showstu}
if (showstu == item[2]) {
chipProps.onDelete = () => handleDelete(item[2]);
chipProps.className = classes.chip;
chipProps.clickable = false;
}
return (
<Chip
//for key better to use index as a unique
key={index}
// this is spread operator (https://reactjs.org/docs/jsx-in-depth.html#spread-attributes)
{...chipProps}
variant="outlined"
label={
<Typography variant="caption" color="textSecondary">
{item[0]} {item[1]}
</Typography>
}
icon={<FaceIcon />}
/>
);
})
);
}
O que significa um erro “Não é possível encontrar o símbolo” ou “Não é possível resolver o símbolo”?
George Harrison ficou chateado por suas letras de 'Hurdy Gurdy Man' de Donovan não terem sido usadas