Examples
Real-world usage patterns for Tide v1.2.
Examples
Real-world usage patterns for Tide v1.2.
URL shorthand
Replace verbose fetcher boilerplate with a simple url string. Built-in handler includes credentials, abort, and AuthError detection.
ETag / conditional fetch
Enable etag to send If-None-Match headers. On 304, Tide skips the update — zero bandwidth, zero re-render.
Content deduplication
hashCompare uses djb2 hashing to skip reactive updates when data is identical — prevents unnecessary DOM reconciliation.
Reactive key (dynamic routes)
Pass a getter function for key and url. Tide re-fetches automatically when either changes.
Reactive key — filter/tab switching
When using reactive keys for tab or filter UIs, each key maintains its own cache entry. Switching tabs fetches fresh data (or hits cache if within cacheTime), and the loading state resets per key.
ℹ️Catatan
Key behaviors: first visit = loading + skeleton, revisit within cacheTime = instant (0ms) from sessionStorage, revisit after cacheTime = fresh fetch. WebSocket pushes update whichever key matches the current reactive value. persist: true survives page refresh.
Conditional fetch (enabled)
Use enabled to pause all activity (fetch, poll, WS) until a condition is met.
wsPath shorthand
Use wsPath instead of a ws function for simple dot-notation extraction from WebSocket messages.
WS backoff + heartbeat
pause() / resume() — lifecycle control
NEW in v1.2.0. Use pause() before optimistic mutations to stop polling and abort inflight requests. Call resume() + await refresh() after the operation to re-sync with the server.
ℹ️Catatan
Without pause(), Tide's polling interval can overwrite your optimistic state mid-operation. Always pair resume() with await refresh() to ensure data convergence before unlocking UI.