import { useMemo } from 'react' ; export function useDaysFromViewport ( viewport ) { return useMemo ( ( ) => { const days = [ ] ; const year = viewport . getFullYear ( ) ; const month = viewport . getMonth ( ) ; let dayLeftPad = viewport . getDay ( ) - 1 ; while ( dayLeftPad >= 0 ) { const date = new Date ( year , month , 1 ) ; date . setDate ( - dayLeftPad ) ; days . push ( date ) ; dayLeftPad -- ; } const daysInMonth = new Date ( year , month + 1 , 0 ) . getDate ( ) ; for ( let i = 1 ; i <= daysInMonth ; i ++ ) { days . push ( new Date ( year , month , i ) ) ; } const lastDate = days [ days . length - 1 ] . getDate ( ) ; const maxDays = 7 * 6 ; for ( let i = 0 ; days . length < maxDays ; i ++ ) { const date = new Date ( year , month , lastDate + i + 1 ) ; days . push ( date ) ; } return days ; } , [ viewport ] ) ; }