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

Fix waste render on connectivity status #2419

Merged
merged 3 commits into from
Sep 23, 2019
Merged

Conversation

compulim
Copy link
Contributor

Fixes #2418.

Changelog Entry

Fixed

  • Fix #2418. Connectivity status should not waste-render every 400 ms, by @compulim in PR #2419

Description

DebouncedConnectivityStatus is causing wasted render for every 400 ms.

Specific Changes

This is due to misunderstanding of useState for assigning a function.

Instead of,

const [predicate, setPredicate] = useState();

setValue(x => x === 'Hello, World!');

It should be,

const [predicate, setPredicate] = useState();

setValue(() => x => x === 'Hello, World!');

This is because, if function is passed to setXXX, React will call the function with the existing value, and use the return value as the new state. If non-function is passed, React will directly set it as new state. This behavior is currently not documented.


  • Testing Added
    • We currently do not have a way to detect how many render done per seconds, etc. We should setup this tool.

@coveralls
Copy link

coveralls commented Sep 22, 2019

Coverage Status

Coverage increased (+0.07%) to 65.306% when pulling 8884da2 on compulim:fix-2418 into 5bf82c3 on microsoft:master.

Copy link
Contributor

@tdurnford tdurnford left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@compulim compulim merged commit e54d213 into microsoft:master Sep 23, 2019
@compulim compulim deleted the fix-2418 branch September 23, 2019 19:48
@compulim compulim mentioned this pull request Oct 4, 2019
13 tasks
@compulim compulim mentioned this pull request Oct 25, 2019
55 tasks
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.

Connectivity status should not waste-render every 400ms
4 participants