import React, { useEffect, useMemo, useState } from 'react'; import { FormattedMessage, useIntl } from 'react-intl'; import Select from '../select/select'; import Stack from '../stack/stack'; import Text from '../text/text'; const getDaysInMonth = (month: number, year: number) => new Date(year, month + 1, 0).getDate(); const currentYear = new Date().getFullYear(); interface IDatepicker { onChange(date: Date): void } /** * Datepicker that allows a user to select month, day, and year. */ const Datepicker = ({ onChange }: IDatepicker) => { const intl = useIntl(); const [month, setMonth] = useState(new Date().getMonth()); const [day, setDay] = useState(new Date().getDate()); const [year, setYear] = useState(2022); const numberOfDays = useMemo(() => { return getDaysInMonth(month, year); }, [month, year]); useEffect(() => { onChange(new Date(year, month, day)); }, [month, day, year]); return (
); }; export default Datepicker;