📅  最后修改于: 2022-03-11 15:02:27.730000             🧑  作者: Mango
import React, { useState } from "react";
import ReactDOM from "react-dom";
import "./styles.css";
const App = () => {
const defaultList = [
{ name: "ItemOne" },
{ name: "ItemTwo" },
{ name: "ItemThree" }
];
const [list, updateList] = useState(defaultList);
const handleRemoveItem = (e) => {
const name = e.target.getAttribute("name")
updateList(list.filter(item => item.name !== name));
};
return (
{list.map(item => {
return (
<>
x
{item.name}
>
);
})}
);
};
const rootElement = document.getElementById("root");
ReactDOM.render( , rootElement);