A dashboard panel shows a timestamp that updates each time the user clicks Refresh.
The panel shows "Last refreshed: Never" on load. Clicking Refresh repeatedly has no effect - the timestamp never updates to the current time.
React doesn't always re-render when you call setState - when does it decide to skip?
React doesn't always re-render when you call setState - when does it decide to skip?
Why this fixes it
`setRefreshKey(refreshKey)` passed the current value of `refreshKey` back into state - React applies `Object.is` to compare the new value against the old one, and because they were identical primitives, it classified the update as a no-op and bailed out without re-rendering or re-running the effect. Changing the call to `setRefreshKey(prev => prev + 1)` produces a new integer on every click, one that is always different from the previous value. React proceeds with the re-render, the effect fires, and the timestamp updates.