Pre-populate the cache before a component subscribes. Useful for hover-triggered preloading, route prefetching, or warming the cache from event handlers.
;; On mouse-enter for a "Next page" button
(rfq/prefetch :books/list {:page 2})
;; Or dispatch ensure-query directly — same thing
(rf/dispatch [::rfq/ensure-query :books/list {:page 2}])
When the component later mounts and subscribes, it finds cached data and skips the fetch:
;; This finds cached data from the prefetch — no loading spinner
@(rf/subscribe [::rfq/query :books/list {:page 2}])
Prefetch respects stale-time and in-flight deduplication — it won't re-fetch data that's already fresh or already being fetched. It does not mark the query as active, so the data is subject to normal GC rules.
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |