Add useRequest for one-shot RPC reads#1618
Closed
mcintyre94 wants to merge 1 commit into
Closed
Conversation
`useRequest(source)` fires a request on mount and re-fires whenever the source identity changes. The source is any `ReactiveActionSource<T>` (the `{ reactiveStore() }` duck-type) — `PendingRpcRequest` is the canonical implementation. Memoize the source with `useMemo` keyed on its inputs; `react-hooks/exhaustive-deps` then catches stale closures by default. Pass `null` to disable the request.
The hook returns `{ data, error, isLoading, refresh, status }`. Status is one of `loading | loaded | error | retrying | disabled`. `refresh()` dispatches on the same underlying action store, so its built-in stale-while-revalidate keeps `data` populated and reports `retrying` during the next attempt — the bridge doesn't need to mirror state externally.
Optional `perRequestSignal: () => AbortSignal` is invoked on every dispatch (initial fire + every `refresh()`). The returned signal is passed through to `.reactiveStore({ perRequestSignal })`. The natural use is per-attempt timeouts (`() => AbortSignal.timeout(5_000)`), which reset on refresh. The factory is held in a ref synced to the latest render — inline closures are fine.
Disabling and unmount cancellation are handled the React-native way: pass `null` for the source (result reports `disabled`), or let the component unmount (effect cleanup aborts the in-flight call). There's no hook-level kill switch — adding one would just duplicate React's lifecycle.
Lifts the `useIsomorphicLayoutEffect` helper that was duplicated in `useAction.ts` into a shared internal module so both hooks (and forthcoming ones) share a single definition.
Exports `RequestResult<T>` and `UseRequestOptions` for plugin hooks that build on this surface.
🦋 Changeset detectedLatest commit: 5662d81 The changes in this PR will be included in the next version bump. This PR includes changesets to release 47 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Member
Author
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
This was referenced May 11, 2026
BundleMonFiles updated (13)
Unchanged files (134)
Total files change +5.2KB +0.99% Final result: ✅ View report in BundleMon website ➡️ |
Contributor
|
Documentation Preview: https://kit-docs-3ivb23eqg-anza-tech.vercel.app |
This was referenced May 11, 2026
This was referenced May 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Problem
Summary of Changes
Fixes #