-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTodoItem.tsx
38 lines (35 loc) · 1.08 KB
/
TodoItem.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import React, { useState } from 'react';
import './style.css';
type Props = {
todo: { name: string; key: string };
handleRemove: (key: string) => void;
handleUpdateSubmit: (content: string, key: string) => void;
};
const TodoItem = ({ todo, handleRemove, handleUpdateSubmit }: Props) => {
const [content, setContent] = useState(todo.name);
const handleUpdateChange = (event) => {
setContent(event.target.value);
};
const handleUndoChanges = () => {
setContent(todo.name);
};
console.log(`render TodoItem ${todo.key}`);
return (
<div style={{ marginBottom: 5, display: 'flex', gap: 5 }}>
<input id={todo.key} value={content} onChange={handleUpdateChange} />
<button className="todo-btns" onClick={() => handleRemove(todo.key)}>
Delete
</button>
<button className="todo-btns" onClick={handleUndoChanges}>
Cancel
</button>
<button
className="todo-btns"
onClick={() => handleUpdateSubmit(content, todo.key)}
>
Update
</button>
</div>
);
};
export default React.memo(TodoItem);