Browse Source

Handling events and component state

master
Ken Schaefer 2 years ago
parent
commit
388f05de4f
  1. 14
      react-complete-guide/src/components/Expenses/ExpenseItem.js

14
react-complete-guide/src/components/Expenses/ExpenseItem.js vendored

@ -1,20 +1,26 @@
import React, { useState } from 'react';
import ExpenseDate from './ExpenseDate';
import Card from '../UI/Card';
import './ExpenseItem.css';
function ExpenseItem(props) {
/*const expenseDate = new Date(2023, 4, 28);
const expenseTitle = 'Car Insurance';
const expenseAmount = 294.67;*/
const [title, setTitle] = useState(props.title);
const clickHandler = () => {
setTitle('Updated!');
console.log(title);
};
return (
<Card className="expense-item">
<ExpenseDate date={props.date} />
<div className="expense-item__description">
<h2>{props.title}</h2>
<h2>{title}</h2>
<div className="expense-item__price">${props.amount}</div>
</div>
<button onClick={clickHandler}>Change Title</button>
</Card>
);
}

Loading…
Cancel
Save