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

Loading…
Cancel
Save