A reusable set of React hooks to manage remote data fetching and CRUD operations in a clean, state-synchronized way.
This package provides a unified API to:
- Fetch paginated data from APIs
- Manage local and remote create/update/delete operations
- Normalize and extract data from API responses
- Handle loading, error, and pagination states
Add the hooks folder to your React Native or React project and import from:
import { useResourceManager } from '@/hooks/resource-manager-hooks';
# 🧰 Resource Manager Hooks
This package contains a set of composable React hooks to simplify **fetching**, **mutation**, and **state management** of remote resources. It enables consistent and reusable handling of async data interactions in React (and React Native) apps.
## 🔍 Overview
### Hooks Included:
- **`useFetch`** – Fetch remote data with pagination, loading, and error state management
- **`useMutation`** – Handle local and remote Create, Update, and Delete operations
- **useResourceManager** – Combines `useFetch` and `useMutation` for full data lifecycle management
---
## 🚀 Quick Start
### 1. Installation
This is a local package, so simply import from your project like:
```ts
import { useResourceManager } from '@/hooks/resourceManager';
Make sure your folder structure includes:
resourceManager/
├── useFetch.ts
├── useMutation.ts
├── useResourceManager.ts
├── resourceManager.types.ts
└── index.ts
const { state, queries, crud } = useResourceManager({
serviceFn: fetchUsers,
dataExtractor: (res) => ({
data: res.users,
totalResults: res.totalCount,
currentPage: res.page,
totalPages: res.totalPages,
}),
remote: {
insertFn: createUser,
updateFn: updateUser,
deleteFn: deleteUser,
},
});
useEffect(() => {
queries.fetchData();
}, []);
<FlatList
data={state.data}
refreshing={state.isRefreshing}
onRefresh={queries.refetchData}
onEndReached={queries.fetchNextPage}
renderItem={({ item }) => (
<UserItem user={item} onDelete={() => crud.deleteItem(item.id)} />
)}
/>
Returns [state, queries, mutations]
state
: data, loading states, errors, paginationqueries
: fetchData, fetchNextPage, refetchDatamutations
: addNewData, updateExistingData, deleteExistingData, etc.
Returns:
state
: fromuseFetch
queries
: fetch-related functionscrud
: mutation functions fromuseMutation
You can override:
dataExtractor
to customize response transformationdataKey
in mutations to extract nested created/updated recordsshouldFetch
to delay or prevent automatic fetching
- Keep
serviceFn
andremote
functions stable (useuseCallback
if needed) - Provide
dataExtractor
to handle complex API response formats - Combine with context providers if global state is needed
Types are declared in resourceManager.types.ts
and exported for use in components or higher-order abstractions.
This is part of the DropIt project. Internal use only.