Skip to content

Commit 2d18a16

Browse files
committed
Add husky
1 parent b89d0f4 commit 2d18a16

File tree

2 files changed

+73
-66
lines changed

2 files changed

+73
-66
lines changed

package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,16 @@
1616
"start": "react-scripts start",
1717
"build": "react-scripts build",
1818
"test": "react-scripts test --env=jsdom",
19-
"eject": "react-scripts eject"
19+
"eject": "react-scripts eject",
20+
"lint": "eslint .",
21+
"lint:fix": "eslint --fix .",
22+
"precommit": "lint-staged"
23+
},
24+
"lint-staged": {
25+
"gitDir": "./",
26+
"linters":{
27+
"src/**/*.jsx": ["eslint --fix", "git add"]
28+
}
2029
},
2130
"homepage": "https://jerryni.github.io/react-redux-practice/build"
2231
}

src/modules/ToDoList.jsx

Lines changed: 63 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,83 @@
11
import React from 'react'
22

33
class ToDoList extends React.Component {
4-
5-
constructor(props) {
6-
super(props)
7-
this.state = {
8-
text: props.text || ''
9-
}
10-
}
114

12-
static defaultProps = {
13-
todos: []
5+
constructor(props) {
6+
super(props)
7+
this.state = {
8+
text: props.text || ''
149
}
10+
}
1511

16-
handleKeyup = e => {
17-
if(e.key === 'Enter'){
18-
let value = e.target.value.trim()
19-
20-
this.props.todos.push({
21-
name: value,
22-
id: new Date().getTime(),
23-
completed: false
24-
})
12+
static defaultProps = {
13+
todos: []
14+
}
2515

26-
this.setState({
27-
text: ''
28-
})
16+
handleKeyup = e => {
17+
if (e.key === 'Enter') {
18+
let value = e.target.value.trim()
2919

30-
console.log(this.props.todos)
31-
}
32-
}
20+
this.props.todos.push({
21+
name: value,
22+
id: new Date().getTime(),
23+
completed: false
24+
})
3325

34-
handleChange = e => {
3526
this.setState({
36-
text: e.target.value
27+
text: ''
3728
})
3829
}
30+
}
3931

40-
handleRemoveTodo = index => {
41-
this.props.todos.splice(index, 1)
32+
handleChange = e => {
33+
this.setState({
34+
text: e.target.value
35+
})
36+
}
4237

43-
this.setState(this.state)
44-
}
38+
handleRemoveTodo = index => {
39+
this.props.todos.splice(index, 1)
4540

46-
onToggle = todo => {
47-
todo.completed = !todo.completed
48-
this.setState(this.state)
49-
}
41+
this.setState(this.state)
42+
}
5043

51-
onToggleAll = e => {
52-
let {checked} = e.target
53-
this.props.todos.forEach(todo => {
54-
todo.completed = checked
55-
})
56-
this.setState(this.state)
57-
}
44+
onToggle = todo => {
45+
todo.completed = !todo.completed
46+
this.setState(this.state)
47+
}
5848

59-
render() {
60-
let {todos} = this.props
61-
return (
62-
<div>
63-
<input type="checkbox" onChange={this.onToggleAll}/>
64-
<input type="text"
65-
onKeyUp={this.handleKeyup}
66-
onChange={this.handleChange}
67-
value={this.state.text}/>
68-
<ul>
69-
{todos.map( (todo, index) =>
70-
<li key={todo.id}>
71-
<label>
72-
<input type="checkbox" checked={todo.completed}
73-
onChange={()=> {this.onToggle(todo)}}/>
74-
{todo.name}
75-
</label>
49+
onToggleAll = e => {
50+
let { checked } = e.target
51+
this.props.todos.forEach(todo => {
52+
todo.completed = checked
53+
})
54+
this.setState(this.state)
55+
}
7656

77-
<span className="close" onClick={() => {this.handleRemoveTodo(index)}}>X</span>
78-
</li>
79-
)}
80-
</ul>
81-
</div>
82-
)
83-
}
57+
render() {
58+
let { todos } = this.props
59+
return (
60+
<div>
61+
<input type="checkbox" onChange={this.onToggleAll} />
62+
<input type="text"
63+
onKeyUp={this.handleKeyup}
64+
onChange={this.handleChange}
65+
value={this.state.text} />
66+
<ul>
67+
{todos.map((todo, index) =>
68+
<li key={todo.id}>
69+
<label>
70+
<input type="checkbox" checked={todo.completed}
71+
onChange={() => { this.onToggle(todo) }} />
72+
{todo.name}
73+
</label>
74+
75+
<span className="close" onClick={() => { this.handleRemoveTodo(index) }}>X</span>
76+
</li>
77+
)}
78+
</ul>
79+
</div>
80+
)
81+
}
8482
}
8583
export default ToDoList

0 commit comments

Comments
 (0)