Heim > Fragen und Antworten > Hauptteil
P粉8183062802023-08-31 11:54:52
就像 steve 所说的
在新版本中不接受 renderDay 属性。相反必须使用插槽。 StaticDatePicker 的代码
import React, { useState } from "react"; import dayjs from "dayjs"; import { useReadAllEvent } from "../hooks/useEvent.mjs"; import { Box } from "@mui/material"; import { styled } from "@mui/material/styles"; import { Loading } from "../pages/index.mjs"; import { EventCard } from "./index.mjs"; import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs"; import { LocalizationProvider } from "@mui/x-date-pickers/LocalizationProvider"; import { PickersDay } from "@mui/x-date-pickers/PickersDay"; import { StaticDatePicker } from "@mui/x-date-pickers/StaticDatePicker"; const HighlightedDay = styled(PickersDay)(({ theme }) => ({ "&.Mui-selected": { backgroundColor: theme.palette.primary.main, color: theme.palette.primary.contrastText, }, })); //higlight the dates in highlightedDays arra const ServerDay = (props) => { const { highlightedDays = [], day, outsideCurrentMonth, ...other } = props; const isSelected = !props.outsideCurrentMonth && highlightedDays.includes(day.format("YYYY-MM-DD")); return ( <HighlightedDay {...other} outsideCurrentMonth={outsideCurrentMonth} day={day} selected={isSelected} /> ); }; const SessionBooking = ({ doctor }) => { const [value, setValue] = useState(""); const [highlightedDays, setHighlitedDays] = useState([ "2023-07-01", "2023-07-09", "2023-07-21", "2024-07-12", ]); const today = dayjs(); return ( <Box> <LocalizationProvider dateAdapter={AdapterDayjs}> <StaticDatePicker defaultValue={today} minDate={today} maxDate={today.add(1, "month")} slots={{ day: ServerDay, }} slotProps={{ day: { highlightedDays, }, }} /> </LocalizationProvider> </Box> ); }; export default SessionBooking;