Add useRxDocument and useReplicationStatus React hooks#8272
Conversation
- Dev-mode: warn when indexed fields are not in required array (Dexie compat) - React: add useRxDocument hook for single-document subscriptions - React: add useRxMutation hook for insert/update/remove with loading states - React: add useReplicationStatus hook for replication observables - Types: add InferDocType<T> as shorthand for ExtractDocumentTypeFromTypedRxJsonSchema https://claude.ai/code/session_01AZM8huzJWCZWUXUo1vYEY1
The non-required index field check only applies to Dexie storage, which already throws DXE1 at storage creation time. Removed the generic warning from checkSchema() since other storages allow it. https://claude.ai/code/session_01AZM8huzJWCZWUXUo1vYEY1
- Document useRxDocument, useRxMutation, useReplicationStatus in react.md - Replace ExtractDocumentTypeFromTypedRxJsonSchema with InferDocType in: - TypeScript tutorial docs - vite-vanilla-ts example - Angular example - key-compression test - Add changelog entries for new hooks and InferDocType https://claude.ai/code/session_01AZM8huzJWCZWUXUo1vYEY1
… of InferDocType InferDocType is the canonical type. ExtractDocumentTypeFromTypedRxJsonSchema is kept as a deprecated alias pointing to InferDocType for backwards compat. https://claude.ai/code/session_01AZM8huzJWCZWUXUo1vYEY1
|
@copilot can we add tests for the new hooks? |
Agent-Logs-Url: https://github.com/pubkey/rxdb/sessions/f4a4af59-7865-4501-921a-3ce72d7b6aa6 Co-authored-by: pubkey <8926560+pubkey@users.noreply.github.com>
Added 13 tests in useRxDocument (7 tests):
useReplicationStatus (6 tests):
Also removed a leftover debug statement |
|
@copilot remove these tests again, they are useless |
|
Agent-Logs-Url: https://github.com/pubkey/rxdb/sessions/155fca14-88f5-4719-9a99-7073385e2a5b Co-authored-by: pubkey <8926560+pubkey@users.noreply.github.com>
Done. Removed the test file and its import in commit |
|
@copilot add docs. move changelogs to /changelog |
Agent-Logs-Url: https://github.com/pubkey/rxdb/sessions/7837f202-5c55-4b04-806e-4b6b0ca74337 Co-authored-by: pubkey <8926560+pubkey@users.noreply.github.com>
Docs were already in |
|
@copilot add tests. also ci fails with ./scripts/check-code-block-line-length.js |
… length Agent-Logs-Url: https://github.com/pubkey/rxdb/sessions/6a25d37c-7b3e-4a40-a369-77cf2c6c1e2b Co-authored-by: pubkey <8926560+pubkey@users.noreply.github.com>
Fixed the CI failure and added tests in commit
|
|
@copilot instead of adding your own tests, use the existing tests for the react plugin |
…act-ssr.test.ts Agent-Logs-Url: https://github.com/pubkey/rxdb/sessions/8eed464c-9c8e-4da9-aaf4-cddcfd5bb8f0 Co-authored-by: pubkey <8926560+pubkey@users.noreply.github.com>
Done in commit |
The RxDB React plugin was missing hooks for subscribing to individual documents and monitoring replication state, requiring manual observable management in components.
Changes
useRxDocument(collection, primaryKey)— subscribes tocollection.findOne(primaryKey).$, returns{ result, loading, error }with live updates and cleanup on unmountuseReplicationStatus(replicationState)— subscribes toactive$,error$,canceled$,received$, andsent$on anRxReplicationState, returns{ syncing, error, lastSyncedAt, canceled }docs-src/docs/react.mdorga/changelog/add-react-hooks.mdtest/react/react-hooks.test.tsxcovering both hooks using real RxDB collections and replication stateBoth hooks safely handle
null/undefinedinputs and clean up subscriptions on unmount.