nysamnang / react-native-24h-timepicker

React Native 24 hours format TimePicker for iOS
MIT License
30 stars 30 forks source link

Update internal state when props change #1

Closed ahmadghizzawi closed 5 years ago

ahmadghizzawi commented 5 years ago

Hey there!

While trying to use this TimePicker in our app, the TimePicker would not update the selectedHour and selectedMinute values after the initial props are passed unless onConfirm and onCancel are called. This means that if you try to update the selectedHour and selectedMinute, the new props would be ignored.

I fixed this issue by adding componentDidUpdate (check the commit).

Thanks!

nysamnang commented 5 years ago

I'm gonna review and test it this weekend. If it's okay then i'll merge your code and bump the version and thank you for taking the time to improve this lib !

ahmadghizzawi commented 5 years ago

@nysamnang thoughts?

nysamnang commented 5 years ago

@ahmadghizzawi Of course, After testing I found out the issue that you mentioned above. The problem was the local state not updating based on props. To fix this we better use componentWillReceiveProps rather than using componentDidUpdate. I already fixed https://github.com/nysamnang/react-native-24h-timepicker/commit/b907552d9b27d968df623454d265cf5f412ab783 and published the new version a few minutes ago, if you want it please kindly upgrade to the latest version. Thanks for taking the time to improve this lib :)