-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExpenseItem.js
More file actions
38 lines (31 loc) · 904 Bytes
/
ExpenseItem.js
File metadata and controls
38 lines (31 loc) · 904 Bytes
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
37
38
import React, { useContext } from 'react';
import { TiDelete } from 'react-icons/ti';
import { AppContext } from '../context/AppContext';
const ExpenseItem = (props) => {
const { dispatch } = useContext(AppContext);
const handleDeleteExpense = () => {
dispatch({
type: 'DELETE_EXPENSE',
payload: props.id,
});
};
const increaseAllocation = (name) => {
const expense = {
name: name,
cost: 10,
};
dispatch({
type: 'ADD_EXPENSE',
payload: expense
});
}
return (
<tr>
<td>{props.name}</td>
<td>£{props.cost}</td>
<td><button onClick={event=> increaseAllocation(props.name)}>+</button></td>
<td><TiDelete size='1.5em' onClick={handleDeleteExpense}></TiDelete></td>
</tr>
);
};
export default ExpenseItem;