我有一个按钮,当您单击它时应该从列表中删除一个框,但它不起作用。谁能明白为什么?
const Box = (props) => {
return (
<>
<div id={props.id} style={{height:`${props.height}em`, width:`${props.width}em`, backgroundColor: props.color }}>
</div>
<Button onClick={props.removeItem}/>
</>
);
};
export default Box;
const BoxList = () => {
const [boxes, setBoxes] = useState([{height: "", width:"", color:"", id:""}]);
const removeBox = (boxId) => {
const updatedBoxList = boxes.filter(box => box.id !== boxId);
setBoxes(updatedBoxList); // this is where the update should happen
};
const boxesArray = boxes.map((box) => {
return(
<Box width={box.height}
height={box.width}
color={box.color}
id={box.id}
removeItem={removeBox}
/>
)
});
[...]
慕码人8056858
至尊宝的传说
相关分类