-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathTodos.js
29 lines (26 loc) · 981 Bytes
/
Todos.js
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
import React from 'react'
import DebouncedInput from './DebouncedInput'
// The checkbox input uses onClick instead of onChange as recommended by preact wiki
// to prevent flickering.
// https://github.com/developit/preact/wiki/Forms#checkboxes--radio-buttons
const Todo = ({setCompleted, setTitle, remove, todo: {completed, title}}) => (
<li>
<input type='checkbox'
checked={completed}
onClick={(event) => { event.preventDefault(); setCompleted(!completed) }} />
<DebouncedInput timeout={200}
value={title}
onChange={(e) => setTitle(e.target.value)} />
<button onClick={remove} />
</li>
)
export default ({setCompleted, setTitle, remove, todos}) => (
<ul className='todos'>
{todos.map(todo => <Todo key={todo.value.id}
todo={todo.value}
setCompleted={(completed) => setCompleted(todo.path, completed)}
setTitle={(title) => setTitle(todo.path, title)}
remove={() => remove(todo.value.id)}
/>)}
</ul>
)