-
-
Notifications
You must be signed in to change notification settings - Fork 554
/
TodoItem.js
36 lines (30 loc) · 867 Bytes
/
TodoItem.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
30
31
32
33
34
35
36
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { withFirebase } from 'react-redux-firebase'
import './Todo.css'
@withFirebase // pass down props.firebase (firebaseConnect() can also be used)
export default class TodoItem extends Component {
static propTypes = {
todo: PropTypes.object,
id: PropTypes.string
}
toggleDone = () => firebase.set(`/todos/${id}/done`, !todo.done)
delete = (event) => firebase.remove(`/todos/${id}`)
render(){
const { todo, id } = this.props
return (
<li className="Todo">
<input
className="Todo-Input"
type="checkbox"
checked={todo.done}
onChange={this.toggleDone}
/>
{todo.text}
<button className="Todo-Button" onClick={this.delete}>
Delete
</button>
</li>
)
}
}