Reactive Hooks
Smithers includes a reactive SQLite layer that provides React hooks for automatic query re-execution when underlying data changes.useQuery
Hook to execute a reactive query that automatically re-runs when relevant tables are mutated.Signature
Options
Return Type
Return Types
useQueryOne
Hook to get a single row from a query.Signature
useQueryValue
Hook to get a single value from a query.Signature
useMutation
Hook to execute mutations with automatic query invalidation.Signature
Options
Return Type
How Reactivity Works
- Table Tracking: The SQL parser extracts table names from queries
- Subscription: Each
useQuerysubscribes to its relevant tables - Mutation Detection: When
db.run()modifies a table, subscribers are notified - Re-execution: Affected queries automatically re-run
DatabaseProvider
Optionally wrap your app inDatabaseProvider for implicit db access:
Best Practices
Use specific queries
Use specific queries
Select only the columns you need to minimize re-renders:
Use skip for conditional queries
Use skip for conditional queries
Use useQueryOne for single rows
Use useQueryOne for single rows