react-antd-template/src/App.tsx

37 lines
797 B
TypeScript
Raw Normal View History

2022-04-12 09:46:25 +07:00
import { Button } from "antd";
import React from "react";
import "./App.less";
function App() {
2022-04-12 09:46:25 +07:00
const [coms, setComs] = React.useState<any>([]);
const onCreate = () => {
setComs([
...coms,
{ id: coms.length * Math.random(), text: `New: ${Math.random()}` },
]);
};
const onRemove = (com: any) => {
setComs(coms.filter((c: any) => c.id !== com.id));
};
return (
<div className="App">
<header className="App-header">
2022-04-12 09:46:25 +07:00
<>Hello World</>
<Button onClick={onCreate} type={"primary"}>
Create me
</Button>
{coms.map((com: any) => (
<div key={com.id}>
<Button onClick={() => onRemove(com)}>{com.text}</Button>
</div>
))}
</header>
</div>
);
}
export default App;