반응형
ExpenseList.js 를 생성해서
조건 명령문에 따른 코드를 따로 구분했다
ExpenseList.js
import ExpenseItem from './ExpenseItem';
import './ExpenseList.css';
const ExpenseList = (props) => {
let expensesContent = <p>No expenses found.</p>;
if (props.items.length === 0) {
return <h2 className='expenses-list__fallback'>Found no expenses.</h2>
}
return <ul className='expenses-list'>
{
props.items.map((expense) => (
<ExpenseItem key={expense.id} title={expense.title} amount={expense.amount} date={expense.date} id={expense.id} />
))
}
</ul>
}
export default ExpenseList;
Expenses.js
import ExpensesFilter from "./ExpensesFilter";
import ExpenseList from "./ExpenseList";
import Card from "../UI/Card";
import { useState } from 'react';
import "./Expenses.css";
function Expenses(props) {
const [filteredYear, setFilteredYear] = useState('2023');
const filterChangeHandler = (selectedYear) => {
setFilteredYear(selectedYear);
}
const filteredList = props.items.filter(item => item.date.getFullYear() === Number(filteredYear));
return <Card className="expenses">
<ExpensesFilter selected={props.selected} onChangeFilter={filterChangeHandler} />
<ExpenseList items={filteredList} />
</Card>
}
export default Expenses;
반응형
'온라인 강의 > React 완벽 가이드 [Udemy]' 카테고리의 다른 글
79. 동적 스타일 추가하기 (0) | 2023.06.05 |
---|---|
78. 데모 앱: 차트 추가하기 (0) | 2023.06.05 |
76. 연습하기 : 조건부 내용 (정답) (0) | 2023.06.05 |
75. 연습하기 : 조건부 내용 (문제) (0) | 2023.06.05 |
74. 조건부 내용 출력하기 (0) | 2023.06.04 |