const ExpenseItem = (props) => {
const [title, setTitle] = useState(props.title);
const date = props.date;
const amount = props.amount;
function clickHandler(){
setTitle("Updated");
console.log(title);
}
return (
<Card className='expense-item'>
<ExpenseCalender
month = {date.toLocaleString("default", {month: "long"})}
day = {date.toLocaleString("default", {day: "2-digit"})}
year = {date.getFullYear()}
/>
<div className='expense-item__description'>
<h2>{title}</h2>
<div className='expense-item__price'>{`$${amount}`}</div>
</div>
<button onClick={clickHandler}>Change title</button>
</Card>
)
}
expected that console.log(title) will give output as 'Updated'
But it was rendering the old title i.e the title data from the props.