Search code examples
iosreact-nativetimepicker

Stange behavior of time in @react-native-community/datetimepicker IOS device


I am having a very strange issue in the IOS device for @react-native-community/datetimepicker while using "TIME" mode.

Whenever I change the time it automatically reverted back to the actual time, time reset on changing. Can you please guide how I can fix this issue?

NOTE: ITS ONLY HAVING ISSUE WITH IOS DEVICES.

Attach is the link to the snack so that you can check quickly.

https://snack.expo.dev/@dedevelopers/date-time-picker-issue


Solution

  • To keep the date you need to update the current date in the DatePicker in the onChange callback function like this:

      const onChange = (event, selectedDate) => {
        const currentDate = selectedDate;
        setDate(new Date(selectedDate));
       ....
    }
    

    You can check this fixed snack based on yours :D from here