I am using the below for <DatePicker>. Saw a lot of videos and sandbox where it works fine.
Not sure why I am getting the below error on renderInput
<DatePicker
label="Basic example"
value={selectedDate}
onChange={(newValue) => { setSelectedDate(newValue) }}
renderInput={(props) => <TextField {...props} />}
/>
Type '{ label: string; value: Date; onChange: (newValue: Date) => void; renderInput: (props: any) => Element; }' is not assignable to type 'IntrinsicAttributes & DatePickerProps<Date> & RefAttributes<HTMLDivElement>'.
Property 'renderInput' does not exist on type 'IntrinsicAttributes & DatePickerProps<Date> & RefAttributes<HTMLDivElement>'.ts(2322)
Your renderInput seems to be from MUI v5. It's not on current <DatePicker> API:
https://mui.com/x/api/date-pickers/date-picker/
For MUI v6 and v7, the slots prop should be used to customize the internal HTML components: https://mui.com/x/api/date-pickers/date-picker/#slots
See here for more information: https://mui.com/x/react-date-pickers/custom-components/#overriding-components
Specifically, the textField slot might be the one you want?
Note that there is also a slotProps prop, to pass through to textField in this example:
<DatePicker
{...otherProps}
slots={{
// Override default <TextField /> with a custom one
textField: CustomTextField,
}}
slotProps={{
// Pass props `variant={"filled"}` to the `textField` slot
textField: { variant: "filled" },
}}
/>
renderInput is the prop used in @mui/x-date-pickers v5 and since v6 were launched it's replaced with customization through slots.
So, equivalent to renderInput in a new version is:
<DatePicker
{...props}
slots={{
textField: textFieldProps => <CustomTextField {...textFieldProps} />
}}
/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With