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

The problem about TimePicker update props #134

Open
sekizlipenguen opened this issue Sep 4, 2020 · 1 comment
Open

The problem about TimePicker update props #134

sekizlipenguen opened this issue Sep 4, 2020 · 1 comment

Comments

@sekizlipenguen
Copy link

Hi,

The problem that about props can be solved, with code which is below;

src/TimePicker.js add.

    static getDerivedStateFromProps(nextProps, current_state) {
        if (nextProps.initDate != current_state.selectedDate) {
            const getInfo = self.update(nextProps);
            return getInfo;
        }
        return null;
    }

    update(props) {
        const {initDate, format24, minutes} = props;
        const selectedDate = initDate ? new Date(initDate) : new Date();
        const time12format = hourTo12Format(selectedDate.getHours());
        const time24format = selectedDate.getHours();
        const hours = self.props.hours || getHoursArray(format24);
        const selectedHourIndex = format24 ? time24format : Number(time12format[0]) - 1;
        const minutesCount = minutes ? minutes.length : 12;
        const selectedMinuteIndex = Math.round(
            selectedDate.getMinutes() / (HOUR / minutesCount),
        );
        const selectedAmIndex = time12format[1] === AM ? 0 : 1;
        return {selectedDate, selectedHourIndex, selectedMinuteIndex, selectedAmIndex};
    }
@zienna
Copy link

zienna commented Dec 14, 2021

it breaks everything....

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

2 participants