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

Using state variable for startMonth doesn't update the day picker #2337

Closed
the-marolie opened this issue Aug 2, 2024 · 1 comment · Fixed by #2343
Closed

Using state variable for startMonth doesn't update the day picker #2337

the-marolie opened this issue Aug 2, 2024 · 1 comment · Fixed by #2343
Assignees
Labels
bug Bug or Bug fixes
Milestone

Comments

@the-marolie
Copy link

the-marolie commented Aug 2, 2024

If we use a state variable for startMonth, the day picker doesn't update the initial month

Code

import { DayPicker } from 'react-day-picker';
import {useState, useEffect} from  'react';
import 'react-day-picker/dist/style.css';
import "./styles.css";

export default function App() {
  const [startMonth, setStartMonth] = useState('');

  useEffect(() => {
    setStartMonth(new Date(2024,2));
  }, [])

  return (
    <div className="App">
      <DayPicker
          mode="single"
          className="day-picker"
          startMonth={startMonth}
          defaultMonth={startMonth}
        />
    </div>
  );
}

sandbox link - https://codesandbox.io/p/sandbox/strange-benz-vsh96j

Expected Behavior

The initial month in calendar updates if the state variable is updated

Actual Behavior

The initial month displayed s the value set during state variable

Screenshots

image
image

@gpbl gpbl added the bug Bug or Bug fixes label Aug 2, 2024
@gpbl gpbl added this to the v9.0.7 milestone Aug 2, 2024
@gpbl gpbl added the to investigate Needs more investigation from the mantainers label Aug 2, 2024
@gpbl gpbl self-assigned this Aug 4, 2024
@gpbl gpbl removed the to investigate Needs more investigation from the mantainers label Aug 4, 2024
@gpbl gpbl linked a pull request Aug 4, 2024 that will close this issue
@gpbl gpbl closed this as completed in #2343 Aug 4, 2024
@gpbl
Copy link
Owner

gpbl commented Sep 7, 2024

Hi there!

I had to revert in #2429 the fix for this change as it caused other problems. I'm not sure if this is actually a bug: When changing startMonth or endMonth, what should happen to the currently selected days? Which month should display if the calendar has already been navigated?

A workaround is to control the month using the onMonthChange and month props.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug or Bug fixes
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants