Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Calling forceUpdate twice in succession doesn't force a re-render #9

Closed
latviancoder opened this issue Jun 13, 2019 · 4 comments
Closed
Assignees
Labels
bug Something isn't working
Milestone

Comments

@latviancoder
Copy link

Here is codesandbox with example:

https://codesandbox.io/s/tender-noether-cnvrz

I assume this happens because React batches two state updates and because in the end state stays the same (true -> false -> true) rerender doesn't happen at all.

@ramblehead
Copy link

const [, doUpdate] = useState(now());
const update = useCallback((): void => doUpdate(now()), [doUpdate]);

// ...
// Call update() as required

now() could be one of the following:
const now = () => performance.now();
or
import now from 'performance-now';

The second variant is useful in SSR.

@latviancoder
Copy link
Author

Or you could simply increment a number the way @sophiebits suggests here:

https://mobile.twitter.com/sophiebits/status/1141935418893463553

@quisido
Copy link
Owner

quisido commented Jun 21, 2019

The number increment was the original implementation. Sophie would be a great citation for that.

@quisido
Copy link
Owner

quisido commented Jun 23, 2019

Thank you for addressing this issue. This will be fixed in 1.0.6 today. :)

@quisido quisido self-assigned this Jun 23, 2019
@quisido quisido added the bug Something isn't working label Jun 23, 2019
@quisido quisido added this to the 1.0.6 milestone Jun 23, 2019
quisido added a commit that referenced this issue Jun 23, 2019
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants