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

Do not cause rerender when fromNowText has not changed #904

Merged
merged 1 commit into from
Dec 19, 2024

Conversation

ddecrulle
Copy link
Contributor

@ddecrulle ddecrulle commented Dec 19, 2024

There was a re-render of the entire component using useFromNow every second. To test this, you can simply add a console.log("render") in a component that uses useFromNow (e.g., MyServicesRunningTime). You will notice a render logged in the console every second.

With this fix, the component will re-render only when the value returned by the hook changes.

@ddecrulle ddecrulle requested a review from garronej December 19, 2024 10:48
@garronej
Copy link
Contributor

Agreed, this a much better implementation.

We could even go a step futher and using the dom to update the value instead of trigerring re-render but it would make the hook API less flexible.

@garronej garronej merged commit ae775c0 into main Dec 19, 2024
7 checks passed
@garronej garronej deleted the fix-rerender-issue branch December 19, 2024 12:22
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

Successfully merging this pull request may close these issues.

2 participants