function AgeCalculator() { const [birthdate, setBirthdate] = useState(''); const [age, setAge] = useState(null); const calculateAge = () => { const birth = new Date(birthdate); const today = new Date(); let years = today.getFullYear() - birth.getFullYear(); let months = today.getMonth() - birth.getMonth(); let days = today.getDate() - birth.getDate(); if (days < 0) { months--; days += new Date(today.getFullYear(), today.getMonth(), 0).getDate(); } if (months < 0) { years--; months += 12; } const totalDays = Math.floor((today - birth) / (1000 * 60 * 60 * 24)); setAge({ years, months, days, totalDays }); }; return (