@hf-chimera/react 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +241 -241
- package/package.json +49 -47
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Hewston Fox
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,241 +1,241 @@
|
|
|
1
|
-
# ChimeraEntityStore React Integration
|
|
2
|
-
|
|
3
|
-
This package provides React hooks for seamless integration with ChimeraEntityStore, enabling reactive data management in React applications.
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- **React Hooks**: Custom hooks for managing ChimeraEntityStore queries
|
|
8
|
-
- **TypeScript Support**: Full type safety with TypeScript
|
|
9
|
-
- **Automatic State Management**: Automatic re-rendering when data changes
|
|
10
|
-
|
|
11
|
-
## Installation
|
|
12
|
-
|
|
13
|
-
```bash
|
|
14
|
-
# Install both the core store and React adapter
|
|
15
|
-
npm install @hf-chimera/store @hf-chimera/react
|
|
16
|
-
|
|
17
|
-
# React is a peer dependency
|
|
18
|
-
npm install react
|
|
19
|
-
|
|
20
|
-
# Or install all at once
|
|
21
|
-
npm install @hf-chimera/store @hf-chimera/react react
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
## Usage
|
|
25
|
-
|
|
26
|
-
### For React Applications
|
|
27
|
-
|
|
28
|
-
Import from the React-specific entry point:
|
|
29
|
-
|
|
30
|
-
```tsx
|
|
31
|
-
import { createChimeraHooks } from "@hf-chimera/store/react";
|
|
32
|
-
// In your app, call createChimeraHooks(store) and export the returned hooks
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
### For Non-React Applications
|
|
36
|
-
|
|
37
|
-
Import from the main package:
|
|
38
|
-
|
|
39
|
-
```ts
|
|
40
|
-
import { createChimeraEntityStore } from "@hf-chimera/store";
|
|
41
|
-
import { createChimeraStoreHooks } from "@hf-chimera/react";
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
## Quick Start
|
|
45
|
-
|
|
46
|
-
### 1. Prepare hooks for the store
|
|
47
|
-
|
|
48
|
-
Use the `createChimeraStoreHooks` function to create hooks for your entity store:
|
|
49
|
-
|
|
50
|
-
```ts
|
|
51
|
-
import { createChimeraStoreHooks } from "@hf-chimera/react";
|
|
52
|
-
import { createChimeraEntityStore } from "@hf-chimera/store";
|
|
53
|
-
|
|
54
|
-
// Define your entity type
|
|
55
|
-
type Customer = {
|
|
56
|
-
id: number;
|
|
57
|
-
name: string;
|
|
58
|
-
email: string;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
// Create your entity store instance
|
|
62
|
-
const customerStore = createChimeraEntityStore<"customer", Customer>({
|
|
63
|
-
name: "customer",
|
|
64
|
-
idGetter: "id",
|
|
65
|
-
async collectionFetcher(params, requestParams) {
|
|
66
|
-
const response = await fetch("/api/customers", {
|
|
67
|
-
method: "POST",
|
|
68
|
-
headers: { "Content-Type": "application/json" },
|
|
69
|
-
body: JSON.stringify({ filter: params.filter, order: params.order }),
|
|
70
|
-
signal: requestParams.signal,
|
|
71
|
-
});
|
|
72
|
-
return { data: await response.json() };
|
|
73
|
-
},
|
|
74
|
-
async itemFetcher(params, requestParams) {
|
|
75
|
-
const response = await fetch(`/api/customers/${params.id}`, {
|
|
76
|
-
signal: requestParams.signal,
|
|
77
|
-
});
|
|
78
|
-
return { data: await response.json() };
|
|
79
|
-
},
|
|
80
|
-
// ... other CRUD operations
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
// Create hooks bound to your customer store
|
|
84
|
-
// This generates: useChimeraCustomerStore, useChimeraCustomerCollection, useChimeraCustomerItem
|
|
85
|
-
export const {
|
|
86
|
-
useChimeraCustomerStore,
|
|
87
|
-
useChimeraCustomerCollection,
|
|
88
|
-
useChimeraCustomerItem,
|
|
89
|
-
} = createChimeraStoreHooks(customerStore);
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
### 2. Use Collection Queries
|
|
93
|
-
|
|
94
|
-
```tsx
|
|
95
|
-
import { useChimeraCustomerCollection } from "./store";
|
|
96
|
-
|
|
97
|
-
function CustomerList() {
|
|
98
|
-
const customers = useChimeraCustomerCollection({
|
|
99
|
-
filter: { status: "active" },
|
|
100
|
-
order: [{ field: "name", direction: "asc" }],
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
if (!customers.ready) return <div>Loading...</div>;
|
|
104
|
-
if (customers.lastError)
|
|
105
|
-
return <div>Error: {String(customers.lastError)}</div>;
|
|
106
|
-
|
|
107
|
-
return (
|
|
108
|
-
<div>
|
|
109
|
-
{customers.map((customer) => (
|
|
110
|
-
<div key={customer.id}>
|
|
111
|
-
{customer.name}
|
|
112
|
-
<button onClick={() => customers.delete(customer.id)}>Delete</button>
|
|
113
|
-
</div>
|
|
114
|
-
))}
|
|
115
|
-
<button onClick={() => customers.create({ name: "New Customer" })}>
|
|
116
|
-
Add Customer
|
|
117
|
-
</button>
|
|
118
|
-
</div>
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
### 3. Use Item Queries
|
|
124
|
-
|
|
125
|
-
```tsx
|
|
126
|
-
import { useChimeraCustomerItem } from "./store";
|
|
127
|
-
|
|
128
|
-
function CustomerDetail({ customerId }: { customerId: string }) {
|
|
129
|
-
const customer = useChimeraCustomerItem(customerId);
|
|
130
|
-
|
|
131
|
-
if (!customer.ready) return <div>Loading...</div>;
|
|
132
|
-
if (customer.lastError) return <div>Error: {String(customer.lastError)}</div>;
|
|
133
|
-
if (!customer.data) return <div>Customer not found</div>;
|
|
134
|
-
|
|
135
|
-
const handleUpdate = () => {
|
|
136
|
-
customer.mutable.name = "Updated Name";
|
|
137
|
-
customer.commit();
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
return (
|
|
141
|
-
<div>
|
|
142
|
-
<h3>{customer.data.name}</h3>
|
|
143
|
-
<button onClick={handleUpdate}>Update Name</button>
|
|
144
|
-
</div>
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
### 4. Using with Query Builder
|
|
150
|
-
|
|
151
|
-
You can use the `ChimeraQueryBuilder` with React hooks by passing a builder function instead of the query descriptor. This provides a more fluent and type-safe API:
|
|
152
|
-
|
|
153
|
-
```tsx
|
|
154
|
-
import { useChimeraCollection, useChimeraItem } from "./store";
|
|
155
|
-
|
|
156
|
-
function ActiveUsers() {
|
|
157
|
-
// Pass a builder function - the hook will call it and build the query
|
|
158
|
-
const activeUsers = useChimeraCollection("customer", (q) => {
|
|
159
|
-
q.where("email", "contains", "@example.com").orderBy("createdAt", true);
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
if (!activeUsers.ready) {
|
|
163
|
-
return <div>Loading...</div>;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
return (
|
|
167
|
-
<div>
|
|
168
|
-
{activeUsers.map((user) => (
|
|
169
|
-
<div key={user.id}>{user.name}</div>
|
|
170
|
-
))}
|
|
171
|
-
</div>
|
|
172
|
-
);
|
|
173
|
-
}
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
**Complex Query with Groups:**
|
|
177
|
-
|
|
178
|
-
```tsx
|
|
179
|
-
import { useChimeraCollection } from "./store";
|
|
180
|
-
|
|
181
|
-
function FeaturedOrders() {
|
|
182
|
-
const orders = useChimeraCollection("order", (q) => {
|
|
183
|
-
q.where("status", "eq", "completed")
|
|
184
|
-
// Must be either high value OR from VIP customer
|
|
185
|
-
.group("or", (group) => {
|
|
186
|
-
group
|
|
187
|
-
.where("totalAmount", "gte", 1000)
|
|
188
|
-
.where("customerId", "in", [1, 2, 3]); // VIP customers
|
|
189
|
-
})
|
|
190
|
-
// But not cancelled
|
|
191
|
-
.whereNot("status", "eq", "cancelled")
|
|
192
|
-
.orderBy("totalAmount", true);
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
return (
|
|
196
|
-
<div>
|
|
197
|
-
{orders.map((order) => (
|
|
198
|
-
<div key={order.id}>{order.productName}</div>
|
|
199
|
-
))}
|
|
200
|
-
</div>
|
|
201
|
-
);
|
|
202
|
-
}
|
|
203
|
-
```
|
|
204
|
-
|
|
205
|
-
For more information on using the query builder, see the [ChimeraQueryBuilder documentation](../../qb/README.md).
|
|
206
|
-
|
|
207
|
-
## API Reference
|
|
208
|
-
|
|
209
|
-
### Hooks
|
|
210
|
-
|
|
211
|
-
#### `useChimeraCustomerCollection<Meta>(params, deps?)`
|
|
212
|
-
|
|
213
|
-
Hook for collection queries with automatic state management.
|
|
214
|
-
|
|
215
|
-
**Parameters:**
|
|
216
|
-
|
|
217
|
-
- `entityName: EntityName` - Name of the entity
|
|
218
|
-
- `params: ChimeraCollectionParams | QueryBuilderCreator` - Query parameters or query builder function
|
|
219
|
-
- `deps?: unknown[]` - Optional dependency array for memoization
|
|
220
|
-
|
|
221
|
-
**Returns:** `ChimeraCollectionQuery<Item, OperatorsMap>`, see [ChimeraCollectionQuery documentation](../../../README.md#chimeracollectionquery)
|
|
222
|
-
|
|
223
|
-
#### `useChimeraItem<Store, EntityName, Meta>(entityName, id, meta?)`
|
|
224
|
-
|
|
225
|
-
Hook for individual item queries with automatic state management.
|
|
226
|
-
|
|
227
|
-
**Parameters:**
|
|
228
|
-
|
|
229
|
-
- `entityName: EntityName` - Name of the entity
|
|
230
|
-
- `id: ChimeraEntityId` - Item ID
|
|
231
|
-
- `meta?: Meta` - Optional metadata
|
|
232
|
-
|
|
233
|
-
**Returns:** `ChimeraItemQuery<Item>`, see [ChimeraCollectionQuery documentation](../../../README.md#chimeraitemquery)
|
|
234
|
-
|
|
235
|
-
## Tips
|
|
236
|
-
|
|
237
|
-
1. **Type Safety**: Use `getChimeraTypedHooks` for full type safety
|
|
238
|
-
2. **Error Handling**: Always check `ready` and `lastError` properties
|
|
239
|
-
3. **Optimistic Updates**: Use the `mutable` property for optimistic updates on item queries
|
|
240
|
-
4. **Batch Operations**: Use batch operations for multiple items when possible
|
|
241
|
-
5. **Query Builder**: Use the query builder function syntax for better type safety and readability
|
|
1
|
+
# ChimeraEntityStore React Integration
|
|
2
|
+
|
|
3
|
+
This package provides React hooks for seamless integration with ChimeraEntityStore, enabling reactive data management in React applications.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **React Hooks**: Custom hooks for managing ChimeraEntityStore queries
|
|
8
|
+
- **TypeScript Support**: Full type safety with TypeScript
|
|
9
|
+
- **Automatic State Management**: Automatic re-rendering when data changes
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
# Install both the core store and React adapter
|
|
15
|
+
npm install @hf-chimera/store @hf-chimera/react
|
|
16
|
+
|
|
17
|
+
# React is a peer dependency
|
|
18
|
+
npm install react
|
|
19
|
+
|
|
20
|
+
# Or install all at once
|
|
21
|
+
npm install @hf-chimera/store @hf-chimera/react react
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
### For React Applications
|
|
27
|
+
|
|
28
|
+
Import from the React-specific entry point:
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
import { createChimeraHooks } from "@hf-chimera/store/react";
|
|
32
|
+
// In your app, call createChimeraHooks(store) and export the returned hooks
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### For Non-React Applications
|
|
36
|
+
|
|
37
|
+
Import from the main package:
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import { createChimeraEntityStore } from "@hf-chimera/store";
|
|
41
|
+
import { createChimeraStoreHooks } from "@hf-chimera/react";
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Quick Start
|
|
45
|
+
|
|
46
|
+
### 1. Prepare hooks for the store
|
|
47
|
+
|
|
48
|
+
Use the `createChimeraStoreHooks` function to create hooks for your entity store:
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
import { createChimeraStoreHooks } from "@hf-chimera/react";
|
|
52
|
+
import { createChimeraEntityStore } from "@hf-chimera/store";
|
|
53
|
+
|
|
54
|
+
// Define your entity type
|
|
55
|
+
type Customer = {
|
|
56
|
+
id: number;
|
|
57
|
+
name: string;
|
|
58
|
+
email: string;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// Create your entity store instance
|
|
62
|
+
const customerStore = createChimeraEntityStore<"customer", Customer>({
|
|
63
|
+
name: "customer",
|
|
64
|
+
idGetter: "id",
|
|
65
|
+
async collectionFetcher(params, requestParams) {
|
|
66
|
+
const response = await fetch("/api/customers", {
|
|
67
|
+
method: "POST",
|
|
68
|
+
headers: { "Content-Type": "application/json" },
|
|
69
|
+
body: JSON.stringify({ filter: params.filter, order: params.order }),
|
|
70
|
+
signal: requestParams.signal,
|
|
71
|
+
});
|
|
72
|
+
return { data: await response.json() };
|
|
73
|
+
},
|
|
74
|
+
async itemFetcher(params, requestParams) {
|
|
75
|
+
const response = await fetch(`/api/customers/${params.id}`, {
|
|
76
|
+
signal: requestParams.signal,
|
|
77
|
+
});
|
|
78
|
+
return { data: await response.json() };
|
|
79
|
+
},
|
|
80
|
+
// ... other CRUD operations
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// Create hooks bound to your customer store
|
|
84
|
+
// This generates: useChimeraCustomerStore, useChimeraCustomerCollection, useChimeraCustomerItem
|
|
85
|
+
export const {
|
|
86
|
+
useChimeraCustomerStore,
|
|
87
|
+
useChimeraCustomerCollection,
|
|
88
|
+
useChimeraCustomerItem,
|
|
89
|
+
} = createChimeraStoreHooks(customerStore);
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### 2. Use Collection Queries
|
|
93
|
+
|
|
94
|
+
```tsx
|
|
95
|
+
import { useChimeraCustomerCollection } from "./store";
|
|
96
|
+
|
|
97
|
+
function CustomerList() {
|
|
98
|
+
const customers = useChimeraCustomerCollection({
|
|
99
|
+
filter: { status: "active" },
|
|
100
|
+
order: [{ field: "name", direction: "asc" }],
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
if (!customers.ready) return <div>Loading...</div>;
|
|
104
|
+
if (customers.lastError)
|
|
105
|
+
return <div>Error: {String(customers.lastError)}</div>;
|
|
106
|
+
|
|
107
|
+
return (
|
|
108
|
+
<div>
|
|
109
|
+
{customers.map((customer) => (
|
|
110
|
+
<div key={customer.id}>
|
|
111
|
+
{customer.name}
|
|
112
|
+
<button onClick={() => customers.delete(customer.id)}>Delete</button>
|
|
113
|
+
</div>
|
|
114
|
+
))}
|
|
115
|
+
<button onClick={() => customers.create({ name: "New Customer" })}>
|
|
116
|
+
Add Customer
|
|
117
|
+
</button>
|
|
118
|
+
</div>
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### 3. Use Item Queries
|
|
124
|
+
|
|
125
|
+
```tsx
|
|
126
|
+
import { useChimeraCustomerItem } from "./store";
|
|
127
|
+
|
|
128
|
+
function CustomerDetail({ customerId }: { customerId: string }) {
|
|
129
|
+
const customer = useChimeraCustomerItem(customerId);
|
|
130
|
+
|
|
131
|
+
if (!customer.ready) return <div>Loading...</div>;
|
|
132
|
+
if (customer.lastError) return <div>Error: {String(customer.lastError)}</div>;
|
|
133
|
+
if (!customer.data) return <div>Customer not found</div>;
|
|
134
|
+
|
|
135
|
+
const handleUpdate = () => {
|
|
136
|
+
customer.mutable.name = "Updated Name";
|
|
137
|
+
customer.commit();
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
return (
|
|
141
|
+
<div>
|
|
142
|
+
<h3>{customer.data.name}</h3>
|
|
143
|
+
<button onClick={handleUpdate}>Update Name</button>
|
|
144
|
+
</div>
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### 4. Using with Query Builder
|
|
150
|
+
|
|
151
|
+
You can use the `ChimeraQueryBuilder` with React hooks by passing a builder function instead of the query descriptor. This provides a more fluent and type-safe API:
|
|
152
|
+
|
|
153
|
+
```tsx
|
|
154
|
+
import { useChimeraCollection, useChimeraItem } from "./store";
|
|
155
|
+
|
|
156
|
+
function ActiveUsers() {
|
|
157
|
+
// Pass a builder function - the hook will call it and build the query
|
|
158
|
+
const activeUsers = useChimeraCollection("customer", (q) => {
|
|
159
|
+
q.where("email", "contains", "@example.com").orderBy("createdAt", true);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
if (!activeUsers.ready) {
|
|
163
|
+
return <div>Loading...</div>;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return (
|
|
167
|
+
<div>
|
|
168
|
+
{activeUsers.map((user) => (
|
|
169
|
+
<div key={user.id}>{user.name}</div>
|
|
170
|
+
))}
|
|
171
|
+
</div>
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
**Complex Query with Groups:**
|
|
177
|
+
|
|
178
|
+
```tsx
|
|
179
|
+
import { useChimeraCollection } from "./store";
|
|
180
|
+
|
|
181
|
+
function FeaturedOrders() {
|
|
182
|
+
const orders = useChimeraCollection("order", (q) => {
|
|
183
|
+
q.where("status", "eq", "completed")
|
|
184
|
+
// Must be either high value OR from VIP customer
|
|
185
|
+
.group("or", (group) => {
|
|
186
|
+
group
|
|
187
|
+
.where("totalAmount", "gte", 1000)
|
|
188
|
+
.where("customerId", "in", [1, 2, 3]); // VIP customers
|
|
189
|
+
})
|
|
190
|
+
// But not cancelled
|
|
191
|
+
.whereNot("status", "eq", "cancelled")
|
|
192
|
+
.orderBy("totalAmount", true);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
return (
|
|
196
|
+
<div>
|
|
197
|
+
{orders.map((order) => (
|
|
198
|
+
<div key={order.id}>{order.productName}</div>
|
|
199
|
+
))}
|
|
200
|
+
</div>
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
For more information on using the query builder, see the [ChimeraQueryBuilder documentation](../../qb/README.md).
|
|
206
|
+
|
|
207
|
+
## API Reference
|
|
208
|
+
|
|
209
|
+
### Hooks
|
|
210
|
+
|
|
211
|
+
#### `useChimeraCustomerCollection<Meta>(params, deps?)`
|
|
212
|
+
|
|
213
|
+
Hook for collection queries with automatic state management.
|
|
214
|
+
|
|
215
|
+
**Parameters:**
|
|
216
|
+
|
|
217
|
+
- `entityName: EntityName` - Name of the entity
|
|
218
|
+
- `params: ChimeraCollectionParams | QueryBuilderCreator` - Query parameters or query builder function
|
|
219
|
+
- `deps?: unknown[]` - Optional dependency array for memoization
|
|
220
|
+
|
|
221
|
+
**Returns:** `ChimeraCollectionQuery<Item, OperatorsMap>`, see [ChimeraCollectionQuery documentation](../../../README.md#chimeracollectionquery)
|
|
222
|
+
|
|
223
|
+
#### `useChimeraItem<Store, EntityName, Meta>(entityName, id, meta?)`
|
|
224
|
+
|
|
225
|
+
Hook for individual item queries with automatic state management.
|
|
226
|
+
|
|
227
|
+
**Parameters:**
|
|
228
|
+
|
|
229
|
+
- `entityName: EntityName` - Name of the entity
|
|
230
|
+
- `id: ChimeraEntityId` - Item ID
|
|
231
|
+
- `meta?: Meta` - Optional metadata
|
|
232
|
+
|
|
233
|
+
**Returns:** `ChimeraItemQuery<Item>`, see [ChimeraCollectionQuery documentation](../../../README.md#chimeraitemquery)
|
|
234
|
+
|
|
235
|
+
## Tips
|
|
236
|
+
|
|
237
|
+
1. **Type Safety**: Use `getChimeraTypedHooks` for full type safety
|
|
238
|
+
2. **Error Handling**: Always check `ready` and `lastError` properties
|
|
239
|
+
3. **Optimistic Updates**: Use the `mutable` property for optimistic updates on item queries
|
|
240
|
+
4. **Batch Operations**: Use batch operations for multiple items when possible
|
|
241
|
+
5. **Query Builder**: Use the query builder function syntax for better type safety and readability
|
package/package.json
CHANGED
|
@@ -1,48 +1,50 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
2
|
+
"name": "@hf-chimera/react",
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "Cross-end reactivity API - React adapter",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "hewston",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"reactivity",
|
|
9
|
+
"reactive",
|
|
10
|
+
"react",
|
|
11
|
+
"hooks",
|
|
12
|
+
"typescript",
|
|
13
|
+
"state-management"
|
|
14
|
+
],
|
|
15
|
+
"type": "module",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"main": "./dist/index.cjs",
|
|
18
|
+
"module": "./dist/index.js",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"require": "./dist/index.cjs",
|
|
23
|
+
"import": "./dist/index.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/hf-chimera/store/issues"
|
|
31
|
+
},
|
|
32
|
+
"repository": {
|
|
33
|
+
"url": "https://github.com/hf-chimera/store"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
37
|
+
"@hf-chimera/store": "~0.2.0"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@hf-chimera/adapters-shared": "~0.2.1"
|
|
41
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public",
|
|
44
|
+
"provenance": true
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build": "tsdown",
|
|
48
|
+
"changeset:patch": "node ../../../scripts/changeset-patch.mjs @hf-chimera/react"
|
|
49
|
+
}
|
|
50
|
+
}
|