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

Memoized equal check should check a date's milliseconds #532

Merged
merged 1 commit into from
Feb 26, 2021
Merged

Memoized equal check should check a date's milliseconds #532

merged 1 commit into from
Feb 26, 2021

Conversation

sandergo90
Copy link
Contributor

Overview

Comparing two dates is not possible using the === operator. When you would like to check the equality of two dates, you need to use the getTime() method. Our component was still re-rendering before comparing dates with getTime().

Object equality isn't tested by the internal value of the object, but by identity. In other words, if it isn't the exact same copy of the Date object, it isn't considered equal.

Here we compare the return values of getTime. The getTime method returns an integer representing the number of milliseconds since midnight of January 1, 1970 (the beginning of the Unix epoch).

@mmazzarolo
Copy link
Owner

Dude, thanks! This has probably never been updated since the time the prop was a number (unix epoch) instead of Date.

@mmazzarolo
Copy link
Owner

Now this makes me wonder: was the wrong memoization actually fixing the bug react-native-datetimepicker/datetimepicker#54 ?

@mmazzarolo
Copy link
Owner

I can't reproduce it even with the right memoization check (from this PR) so I'm merging it.
Just to be safe, I'm bumping it as a minor.

@mmazzarolo mmazzarolo merged commit 40f7e68 into mmazzarolo:master Feb 26, 2021
github-actions bot pushed a commit that referenced this pull request Feb 26, 2021
# [9.2.0](v9.1.0...v9.2.0) (2021-02-26)

### Features

* Fix memoized equal check on Android ([#532](#532)) ([40f7e68](40f7e68))
@github-actions
Copy link

🎉 This PR is included in version 9.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@sandergo90
Copy link
Contributor Author

No problem! ;) In our app, we have websockets pushing new data. Our parent component is using redux selectors to listen to data changes that websockets push. When websocket pushes new data, the parent is re-rendered, causing the datetimepicker to also re-render, even if the date was correct.

@sandergo90 sandergo90 deleted the fix/memoized-date branch February 26, 2021 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants