const todos = [
[
{ id: 1, value: "Wish dishes" },
{ id: 2, value: "Clean the face"},
{ id: 3, value: "Running"},
{ id: 4, value: "Studying"}
],
[
{ id: 1, value: "Wish dishes" },
{ id: 3, value: "Running"},
{ id: 4, value: "Studying"},
{ id: 2, value: "Clean the face"},
],
[
{ id: 4, value: "Studying"},
{ id: 1, value: "Wish dishes" },
{ id: 2, value: "Clean the face"},
{ id: 3, value: "Running"},
]
]
const App = () => {
const [items, setItems] = React.setState(todos)
React.useEffect(() => {
const interval = setInterval(() => {
const random = Math.floor(Math.random() * 3)
setItems(todos[random])
}, 1000)
}, [])
const handleDoneClick = (todo) => {
setItems(items => items.filter((item) => item !== todo))
}
const handleRestoreClick = () => {
setItems((items) => {
...items,
todos.find((todo) => !items.include(todo))
})
}
return (
<>
{items.map((todo, index) =>
<div key={todo.id}>
<button onClick={() => handleDoneClick(todo)}>{todo.value}</button>
</div>
)}
<br />
<button onClick={handleRestoreClick}>Restore</button>
</>
)
}