Skip to content

Commit

Permalink
fix: prevent redundant rerenders in time grid (#365)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomosterlund committed Apr 20, 2024
1 parent 9e5cf87 commit e63b813
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/calendar/src/components/week-grid/time-grid-day.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CalendarEventInternal } from '@schedule-x/shared/src/interfaces/calendar/calendar-event.interface'
import { useContext } from 'preact/hooks'
import { useContext, useEffect, useState } from 'preact/hooks'
import { AppContext } from '../../utils/stateful/app-context'
import TimeGridEvent from './time-grid-event'
import { sortEventsByStartAndEnd } from '../../utils/stateless/events/sort-by-start-date'
Expand Down Expand Up @@ -39,7 +39,13 @@ export default function TimeGridDay({ calendarEvents, date }: props) {
}

const sortedEvents = calendarEvents.sort(sortEventsByStartAndEnd)
const eventsWithConcurrency = handleEventConcurrency(sortedEvents)
const [eventsWithConcurrency, setEventsWithConcurrency] = useState<
CalendarEventInternal[]
>([])

useEffect(() => {
setEventsWithConcurrency(handleEventConcurrency(sortedEvents))
}, [calendarEvents])

const handleOnClick = (e: MouseEvent) => {
if (!$app.config.callbacks.onClickDateTime) return
Expand Down

0 comments on commit e63b813

Please sign in to comment.