📅  最后修改于: 2022-03-11 15:02:28.556000             🧑  作者: Mango
const data = ["James", "John", "Jessica", "Jamie"];
function App() {
const [visibilities, setVisibilities] = React.useState(() => data.map((x) => true));
const handleClick = (event) => {
const index = parseInt(event.currentTarget.dataset.index, 10);
const newVisibilities = [...visibilities];
newVisibilities[index] = !newVisibilities[index];
setVisibilities(newVisibilities);
};
return (
{data.map((value, index) => (
Hello {value}, you are {visibilities[index] ? "visible" : "hidden"}!
))}
);
}
ReactDOM.render( , document.querySelector("main"));