Commit b0480c0
committed
Add
SWR-backed counterpart to `useTrackedData`. Takes the same `TrackedDataSpec` (RPC fetch + subscription pair + value mappers) and routes the unified, slot-deduped stream through SWR's `useSWRSubscription`, building a fresh `createReactiveStoreWithInitialValueAndSlotTracking` per subscription.
Returns the same `SlotTaggedValue<TItem>` shape that `useSubscriptionSwr` exports — `data.value` is the unified item produced by the spec's mappers; `data.slot` is the envelope's `context.slot`. Mirrors core `useTrackedData`'s top-level `{ data, slot }` flattened into SWR's `data` slot, and matches `useSubscriptionSwr` so a switch between the two SWR hooks is just a different generic, not a different access pattern.
Either `key === null` or `spec === null` disables the subscription, mirroring `useTrackedData`'s nullable-spec pattern. Options merge SWR's config with `useTrackedData`'s `UseTrackedDataOptions` (`getAbortSignal` for per-attempt signals threaded into the underlying store via `withSignal(signal).connect()`).useTrackedDataSwr to the @solana/react/swr adapter1 parent b1c4037 commit b0480c0
6 files changed
Lines changed: 660 additions & 0 deletions
File tree
- .changeset
- packages/react
- src
- swr
- __tests__
- __typetests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
377 | 377 | | |
378 | 378 | | |
379 | 379 | | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
380 | 406 | | |
381 | 407 | | |
382 | 408 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
0 commit comments