Skip to content

Commit

Permalink
fix: apply ternary operator
Browse files Browse the repository at this point in the history
  • Loading branch information
cjeongmin authored Sep 11, 2024
1 parent 1eeadd3 commit 3a364f7
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions src/components/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,11 @@ export function Calendar({
if (selectedDates.start == null) {
setSelectedDates({ start: date });
} else if (selectedDates.end == null) {
setSelectedDates(({ start }) => {
if (start && start.getTime() < date.getTime()) {
return {
start,
end: date,
};
}
return {
start: date,
end: start,
};
});
setSelectedDates(({ start }) =>
start.getTime() < date.getTime()
? { start, end: date }
: { start: date, end: start }
);
} else {
setSelectedDates({ start: date });
}
Expand All @@ -58,28 +51,28 @@ export function Calendar({
() => (
<>
<button
type='button'
type="button"
onClick={() => {
setNow(new Date(now.getFullYear(), now.getMonth() - 1));
}}
>
<img src='calendar-prev-next.svg' alt='to select previous month' />
<img src="calendar-prev-next.svg" alt="to select previous month" />
</button>
<button
type='button'
type="button"
onClick={() => {
setNow(new Date(now.getFullYear(), now.getMonth() + 1));
}}
>
<img
src='calendar-prev-next.svg'
alt='to select next month'
src="calendar-prev-next.svg"
alt="to select next month"
style={{ rotate: '180deg' }}
/>
</button>
</>
),
[now],
[now]
);

useEffect(() => {
Expand All @@ -98,7 +91,7 @@ export function Calendar({
</styles.header>
<styles.dates>
{DAYS.map((day) => (
<span className='day' key={day}>
<span className="day" key={day}>
{day}
</span>
))}
Expand Down

0 comments on commit 3a364f7

Please sign in to comment.