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

Less complex implementation #2

Closed
donavon opened this issue Nov 8, 2018 · 3 comments
Closed

Less complex implementation #2

donavon opened this issue Nov 8, 2018 · 3 comments

Comments

@donavon
Copy link

donavon commented Nov 8, 2018

wouldn't this work just as well? none of the max nonsense.

const useForceUpdate = () => {
  const [, setIt] = useState(false);
  return () => setIt(it => !it);
};
@quisido
Copy link
Owner

quisido commented Nov 8, 2018

I don't see why not! I've heard that you can just call setIt with no parameters, and it will always cause a re-renders (no shallow comparisons for updating), but I haven't had time to test that.

@donavon
Copy link
Author

donavon commented Nov 8, 2018

It works! So I've ended up here.

const useForceUpdate = () => useState()[1];

@phpnode
Copy link

phpnode commented Dec 18, 2018

also the stuff to prevent integer overflow in the current implementation is probably unnecessary. If your app rerendered 60x per second it would take 4760 years to overflow.

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

3 participants