CRUD Hooks
The hooks package in@repo/crud
provides a collection of React hooks for performing CRUD operations in your components. These hooks are built on top of the CRUD Engine and provide a seamless integration with React.
Features
- Data Fetching: Hooks for fetching data from your data provider
- Data Mutations: Hooks for creating, updating, and deleting data
- Loading States: Automatic handling of loading states
- Error Handling: Consistent error handling across hooks
- Optimistic Updates: Support for optimistic UI updates
- Refetching: Automatic and manual refetching of data
- TypeScript Support: Full TypeScript support with generics
Installation
This package is part of thezopio
monorepo and is available to all applications in the workspace.
Basic Usage
Setting Up the Provider
Before using the hooks, you need to set up the CRUD provider in your application:Data Fetching Hooks
useGetList
TheuseGetList
hook fetches a list of resources from your data provider.
Options
useGetOne
TheuseGetOne
hook fetches a single resource from your data provider.
Options
useGetMany
TheuseGetMany
hook fetches multiple resources by their IDs.
Options
Data Mutation Hooks
useCreate
TheuseCreate
hook creates a new resource in your data provider.
Options
useUpdate
TheuseUpdate
hook updates an existing resource in your data provider.
Options
useDelete
TheuseDelete
hook deletes an existing resource from your data provider.
Options
Advanced Hooks
useMutation
TheuseMutation
hook provides a more flexible way to perform mutations.
Options
useQueryClient
TheuseQueryClient
hook provides access to the query client for advanced use cases.
useCrudEngine
TheuseCrudEngine
hook provides direct access to the CRUD engine.