Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DatePicker shows build time date instead of current date in Next.js 13.5.7 #5460

Open
opapa88 opened this issue Feb 28, 2025 · 0 comments
Open

Comments

@opapa88
Copy link

opapa88 commented Feb 28, 2025

Next.js 13.5.7
"react-datepicker": "^6.6.0"

Why does the DatePicker show the build time date instead of the current date after deployment, while the date inside the div is correct?

For example, the code was deployed on 2025-02-26, and today is 2025-02-28. However, the DatePicker displays 2025-02-26 (in bold), while the date inside the div correctly shows 2025-02-28.

I tried setting the initial date—same result. I also tried using useEffect—same result.

Live result:

https://www.pediatreegle.lt/test3

Here is the code:

'use client'

import React, { useEffect, useState } from 'react';
import DatePicker from 'react-datepicker';
import 'react-datepicker/dist/react-datepicker.css';

export const Test3 = () => {
    const [selectedDate, setSelectedDate] = useState(null);

    useEffect(() => {
        setSelectedDate(new Date());
    }, []);

    const handleSubmit = (event) => {
        event.preventDefault();
        alert(`Selected Date (UTC): ${selectedDate.toUTCString()}\nSelected Date (Locale): ${selectedDate.toLocaleString()}`);
    };

    return (
        <form onSubmit={handleSubmit}>
            <DatePicker
                selected={selectedDate}
                onChange={(date) => setSelectedDate(date)}
                inline
            />
            <button type="submit">Submit</button>
            <div>selected date: {selectedDate ? selectedDate.toLocaleString() : "not selected"}</div>
        </form>
    );
};

export default Test3;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant