API Reference
useFluxTime()
Returns the current time corrected for clock skew between this device and your server — one number, computed once at bootstrap, so a countdown or expiry timer is accurate even on a device with a drifting system clock.
Prerequisites
- FluxProvider mounted above this component — see api/with-flux
- At least one successful bootstrap() call, for clockSkewMs to be non-zero — see step 6
1
Basic usage
Call
useFluxTime() anywhere you'd otherwise reach for Date.now() — a countdown, a booking window, an expiry display.typescript
2
What it actually returns
It's a direct calculation, not a live subscription — calling it gives you the corrected time at that instant, nothing more.
typescript
It won't tick on its own
A component reading useFluxTime() only gets a fresh value when it re-renders. For a visibly ticking countdown, drive re-renders yourself with an interval, as shown next.
3
Driving a ticking countdown
Force a re-render on your own interval, then read
useFluxTime() fresh each tick.typescript
4
Where clockSkewMs comes from
Computed once per session, during
flux.bootstrap(), by comparing the response's Date header against local time with a half-latency correction.typescript
5
Why this exists
The same correction that powers this hook is also used internally, wherever Flux itself needs to reason about time relative to the server rather than the device.
typescript
6
Before the first bootstrap resolves
If a component reads this hook before
bootstrap() has completed at least once, there's no correction to apply yet — it behaves like plain Date.now() until then.typescript
For how clockSkewMs is computed and stored, see api/bootstrap. For its other consumer — handshake replay timestamp correction — see api/replay.