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

Updating date causes display problems #181

Open
bc-m opened this issue Aug 15, 2022 · 1 comment
Open

Updating date causes display problems #181

bc-m opened this issue Aug 15, 2022 · 1 comment

Comments

@bc-m
Copy link

bc-m commented Aug 15, 2022

Description

Mounting react-timeago and updating the date-state later will result in an incorrect display. As a workaround we have set the "key"-property to "date.now()".

How to reproduce?

Step 1

Open codesandbox: https://codesandbox.io/s/pensive-sea-oy63x2?file=/demo.tsx

You will see this:

Bildschirmfoto 2022-08-15 um 12 15 43

Acutal behavior as expected less than a minute ago. Everything is fine until here.

Step 2

Click on button "set date" updates the state to "new Date()"

You will see this:

Bildschirmfoto 2022-08-15 um 12 15 55

  • Expected: less than a minute ago
  • Actual behavior: less than a minute from now

With the workaround we can fix this behavior until here.

Step 3

Spam clicks on button "sets date" will cause the issue to the worarounded variant too.

Bildschirmfoto 2022-08-15 um 12 17 29

  • Expected: less than a minute ago
  • Actual behavior: less than a minute from now
@bc-m bc-m changed the title Updating the date causes display problems Updating date causes display problems Aug 15, 2022
@mopatches
Copy link

Thank you @bc-m -- this solved our issue as well:

Before:

<TimeAgo date={modifiedAtMs} />

After:

<TimeAgo date={modifiedAtMs} key={modifiedAtMs} />

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