Skip to content

Instantly share code, notes, and snippets.

@VinayakBagaria
Last active February 9, 2019 12:49
Show Gist options
  • Save VinayakBagaria/3fdc019940828681b49e13f93ee5d459 to your computer and use it in GitHub Desktop.
Save VinayakBagaria/3fdc019940828681b49e13f93ee5d459 to your computer and use it in GitHub Desktop.
useState bails out if next value is same as previous one, this is how we can forceUpdate the Component
import React, { useReducer } from 'react';
function Component() {
const [ignored, forceUpdate] = useReducer(x => x + 1, 0);
function handleClick() {
forceUpdate();
}
return (
<div>
{Math.random()}
<br />
<button onClick={handleClick}>Force Update</button>
</div>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment