i got issue with set default value of DatePicker. This is a component for edit object, so, when page is render, all controllers defaultValues are those acquired from the object that you select in the previous component.
I have this atributte on my object:
estimated_close_date: '15-02-2024'
My useEffect where i setValue of all Controllers
useEffect(() => {
getOptionTools()
for (const key in defaultValuesEdit) {
setValue(key, defaultValuesEdit[key])
}
}, [editProblem, setValue])
DatePicker
<Grid item xs={12} md={3}>
<Typography>Estimacion de Cierre</Typography>
<Controller
name="estimated_close_date"
control={control}
rules={{ required: true }}
render={({ field }) => (
<LocalizationProvider dateAdapter={AdapterDayjs} adapterLocale={'en-gb'}>
<DatePicker
slotProps={{ textField: { size: 'small' } }}
onChange={(date) => field.onChange(date)} />
</LocalizationProvider>
)}>
</Controller>
</Grid>
I tried convert estimated_close_date with dayjs, but dosen't work.
I tried with this:
const defaultValuesEdit = editProblem ? {
name: editProblem.name,
description: editProblem.description,
tools: editProblem.tools,
type: editProblem.type,
estimated_close_date: dayjs(editProblem.estimated_close_date)
} : defaultValues
but format dayjs is MM/DD/YYYY and also with config dayjs to DatePicker, this dosen't work to