WatermelonDB hooks #1942
lucaswitch
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
WatermelonDB Hooks Proposal
This idea brings React-style hooks to WatermelonDB, aligning with the hooks philosophy for better state and data management in components.
While WatermelonDB already provides observable components, hooks offer greater flexibility, improved developer experience, and cleaner integration in React components.
Core Assumptions
nullor[]).Key hooks to implement:
useModel– Fetches a model instance by primary key.useQuery– Executes a query and returns the result.useQuerySuspense– Execute a query in suspense way .useModelSuspense– Same asuseModel, but uses Suspense for blocking until the data is available.useInfiniteQuery– Supports infinite scroll behavior, built usinguseQuerywith pagination, and provides callbacks for loading more data (e.g.fetchNext,fetchPrevious).useDatabaseWrite– Receives a callback function that can perform a write in the databaseExample: Using Hooks in a Component
Beta Was this translation helpful? Give feedback.
All reactions