Reputation: 1
I'm using React Big Calendar in my project, but the calendar is misaligned—it.
This is screenshot of the issue: (https://i.sstatic.net/2hGOt8M6.png)
This is my code
import { Calendar, dayjsLocalizer } from 'react-big-calendar' import dayjs from 'dayjs' import { useState } from 'react';
const Tryyy = () => { const localizer = dayjsLocalizer(dayjs)
const [eventList] = useState([
{
start: new Date(2025, 1, 25),
end: new Date(2025, 1, 25),
type: 'leave',
},
]);
return (
<div>
<Calendar
localizer={localizer}
events={eventList}
startAccessor="start"
endAccessor="end"
style={{ height: 500 }}
/>
</div>
)
}
export default Tryyy
It should be look like this: (https://i.sstatic.net/ckob3VgY.png)
Upvotes: 0
Views: 19
Reputation: 1
Looking at your screenshots and code, I see several architectural issues causing the misalignment in your React Big Calendar implementation.
import React, { useState, useCallback, useMemo } from 'react';
import { Calendar, dayjsLocalizer } from 'react-big-calendar';
import dayjs from 'dayjs';
import 'react-big-calendar/lib/css/react-big-calendar.css'; // Critical for layout
const CalendarComponent = () => {
const localizer = useMemo(() => dayjsLocalizer(dayjs), []);
const [view, setView] = useState('month');
const eventList = useMemo(() => [
{
id: 'leave-1', // Add unique ID for reconciliation
title: 'Leave Day', // Required for event display
start: new Date(2025, 1, 25),
end: new Date(2025, 1, 25),
type: 'leave',
},
], []);
const eventStyleGetter = useCallback((event) => ({
style: {
backgroundColor: event.type === 'leave' ? '#3174ad' : '#1976d2',
borderRadius: '4px',
color: 'white',
border: 'none',
display: 'block',
overflow: 'hidden'
}
}), []);
return (
<div className="calendar-container" style={{ height: '100vh' }}>
<Calendar
localizer={localizer}
events={eventList}
startAccessor="start"
endAccessor="end"
titleAccessor="title"
style={{ height: 700 }}
views={['month', 'week', 'day', 'agenda']}
view={view}
onView={setView}
eventPropGetter={eventStyleGetter}
popup
selectable
/>
</div>
);
};
export default CalendarComponent;
Your primary issues:
For more sophisticated implementations, consider extracting event handling logic into custom hooks, implementing context for shared calendar state, and creating specialized event renderers for complex event types.
Upvotes: 0