Skip to content

Commit 48218e0

Browse files
add remove method in react
1 parent 091f33c commit 48218e0

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

index.html

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,16 @@ <h1>Goal</h1>
215215
function List(props) {
216216
return (
217217
<ul>
218-
<li>LIST</li>
218+
{props.items.map((item) => (
219+
<li key={item.id}>
220+
<span>
221+
{item.name}
222+
</span>
223+
<button onClick={() => props.remove(item)} >
224+
X
225+
</button>
226+
</li>
227+
) )}
219228
</ul>
220229
);
221230
}
@@ -233,14 +242,19 @@ <h1>Goal</h1>
233242
id: generateId(),
234243
})
235244
);
236-
}
245+
}
246+
247+
removeItem = (todo) => {
248+
this.props.store.dispatch(removeTodoAction(todo.id))
249+
}
250+
237251
render() {
238252
return (
239253
<div>
240254
<h1>Todo List</h1>
241255
<input type="text" placeholder="add todo" ref={(input) => (this.input = input)} />
242256
<button onClick={this.addItem}>Add ToDo</button>
243-
<List />
257+
<List remove={this.removeItem} items={this.props.todos} />
244258
</div>
245259
);
246260
}
@@ -258,14 +272,18 @@ <h1>Todo List</h1>
258272
id: generateId(),
259273
})
260274
);
261-
}
275+
}
276+
277+
removeItem = (goal) => {
278+
this.props.store.dispatch(removeGoalAction(goal.id))
279+
}
262280
render() {
263281
return (
264282
<div>
265283
<h1>Goals</h1>
266284
<input type="text" placeholder="add goals" ref={(input) => (this.input = input)} />
267285
<button onClick={this.addItem}>Add Goals</button>
268-
<List />
286+
<List remove={this.removeItem} items={this.props.goals} />
269287
</div>
270288
);
271289
}

0 commit comments

Comments
 (0)