hypeserver / react-date-range

A React component for choosing dates and date ranges.
MIT License
2.57k stars 658 forks source link

maxDate can't be updated #570

Open vreallyla opened 2 years ago

vreallyla commented 2 years ago

Subject of the issue

when I try to update maxDate value to useState, maxDate still doesn't change. maybe this also applies to minDate

[BUG] Bug Reproduce Steps

Previously I initialized the value of maxDate with useState and updated it with useEffect for the next 30 days.

const [maxDate, setMaxDate] = useState(new Date()); / /init maxDate +30 days useEffect(() => { setMaxDate(addDays(switchTimeZone({ withTime: false }), 30)); }, []);

I updated it via UseEffect, so every time the value changes maxDate will change to startDate+7 days

// max date setup (30 days / 7 days after selected start date) useEffect(() => { // get data from useState const { startDate, endDate } = dateValue[0] ? dateValue[0] : {}; if (startDate == endDate) setMaxDate(addDays(startDate, 7)); else setMaxDate(addDays(startDate, 30)); }, [ dateValue]);

[BUG] Expected behaviour

maxdate should change according to useState condition

Environment

Package Version: ^1.4.0 React version: 17.0.2 Node version: v17.4.0 Browser: Version 100.0.4896.88