@braine/quantum-query 1.2.5 → 1.2.6

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/README.md CHANGED
@@ -46,7 +46,36 @@ function UserProfile({ id }) {
46
46
 
47
47
  ---
48
48
 
49
- ## 🧠 The "Smart Model" Pattern (Advanced)
49
+ ## 🧠 Mental Model: When to use what?
50
+
51
+ We separate state into two distinct categories.
52
+
53
+ ### 1. Server State (`useQuery`)
54
+ Data that belongs to the server. It is asynchronous, can be stale, and needs caching.
55
+ * **Examples:** User Profile, List of Todos, Search Results.
56
+ * **Tool:** `useQuery`, `useMutation`.
57
+
58
+ ### 2. App State (`createState`)
59
+ Data that belongs to the Interface. It is synchronous and temporary.
60
+ * **Examples:** Is Modal Open?, Current Filter, Form Inputs.
61
+ * **Tool:** `createState`, `useStore`.
62
+
63
+ ### 🌉 The Bridge
64
+ Connect them seamlessly.
65
+ * **Store → Query**: Drive a query with a store signal.
66
+ ```ts
67
+ const { filter } = useStore(uiStore);
68
+ const { data } = useQuery(['items', filter], fetchItems);
69
+ ```
70
+ * **Query → Store**: Sync server data into a store for computed logic.
71
+ ```ts
72
+ const bridge = fromSignal(query.signal);
73
+ // Now you can use 'bridge' inside your Proxy store logic!
74
+ ```
75
+
76
+ ---
77
+
78
+ ## 🏗 The "Smart Model" Pattern (Advanced)
50
79
 
51
80
  Stop splitting your logic between Redux (Client State) and React Query (Server State). **Smart Models** combine state, computed properties, and actions into one reactive entity.
52
81
 
@@ -212,6 +241,71 @@ persistQueryClient({
212
241
 
213
242
  ---
214
243
 
244
+ ## 🚀 Server-Side Rendering (SSR) 🆕
245
+
246
+ Full support for Next.js, Remix, and other SSR frameworks. We provide a simple hydration API to transfer state from server to client.
247
+
248
+ ### Server (Next.js App Router)
249
+ ```tsx
250
+ import { dehydrate, QueryCache, HydrationBoundary } from '@braine/quantum-query';
251
+
252
+ export default async function Page() {
253
+ const client = new QueryCache();
254
+
255
+ // Prefetch data on the server
256
+ await client.prefetch(['user', '1'], fetchUser);
257
+
258
+ // Serialize the cache
259
+ const dehydratedState = dehydrate(client);
260
+
261
+ return (
262
+ <HydrationBoundary state={dehydratedState}>
263
+ <ClientComponent />
264
+ </HydrationBoundary>
265
+ );
266
+ }
267
+ ```
268
+
269
+ ---
270
+
271
+ ## ⚡️ Fine-Grained Selectors (Optimization) 🆕
272
+
273
+ Stop re-rendering your large components. Subscribe **only** to the data you need.
274
+
275
+ ```tsx
276
+ const { data: userName } = useQuery({
277
+ queryKey: ['user', '1'],
278
+ queryFn: fetchUser,
279
+ // Only re-render if 'name' changes!
280
+ // Even if 'age' or 'email' updates in the background.
281
+ select: (user) => user.name
282
+ });
283
+ ```
284
+
285
+ **Why is this better?**
286
+ In other libraries, selectors often run on every render or require manual memoization. In **Quantum-Query**, our Signal-based architecture ensures the component **never even attempts to re-render** unless the specific selected value changes.
287
+
288
+ ---
289
+
290
+ ## 🛠️ DevTools (Debug Like a Pro)
291
+
292
+ Inspect your cache, force refetches, and view active listeners.
293
+
294
+ ```tsx
295
+ import { QuantumDevTools } from '@braine/quantum-query/devtools';
296
+
297
+ function App() {
298
+ return (
299
+ <QueryClientProvider client={client}>
300
+ <YourApp />
301
+ <QuantumDevTools openByDefault={false} />
302
+ </QueryClientProvider>
303
+ );
304
+ }
305
+ ```
306
+
307
+ ---
308
+
215
309
  ## 📚 Documentation
216
310
 
217
311
  * **[API Reference](docs/api.md)**: Full method signatures and options.