I am very new to React JS. I currently have a web page with the a simple DateTimePicker. It works fine. Currently, the datetimepicker shows up as blank, and you can select a date from the dropdown, it'll populate the input and display this date. So what I want to do is instead if having it blank, I want to set the input to today's date right away, so that when I go to the page the datetimepicker's input is not blank - it already displays today's date. I tried a lot of things but they didnt work, in my code below I tried to use setDate(), but it didn't work. I also tried setDate(new Date()), which also didn't work...
function MyDateFunction(props) {
const [canViewDatePicker, setCanViewDatePicker] = useState(
!!props.user.accountExpiryDate
);
const { t } = useTranslation();
return (
<Field>
<HorizontalFlex>
<DateTimePicker
cssClassModifiers={['column', 'is-one-third']}
time={false}
disabled={!canViewDatePicker}
label={t('myLabel')}
Date={('setDate', '0')}
/>
</HorizontalFlex>
</Field>
);
}
The DateTimePicker
that I am using is from react-widgets/lib package
Any ideas much appreciated :)
Yay i figured it out! Inside my <DateTimePicker/>
I had to put defaultValue={new Date()}