@cstar.help/react 0.2.0 → 0.3.0
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/dist/index.cjs +8 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +8 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -412,6 +412,13 @@ function useArticle(slug) {
|
|
|
412
412
|
}
|
|
413
413
|
}
|
|
414
414
|
}, [client, slug]);
|
|
415
|
+
const recordView = (0, import_react10.useCallback)(async () => {
|
|
416
|
+
if (!slug) return;
|
|
417
|
+
try {
|
|
418
|
+
await client.recordView(slug);
|
|
419
|
+
} catch {
|
|
420
|
+
}
|
|
421
|
+
}, [client, slug]);
|
|
415
422
|
(0, import_react10.useEffect)(() => {
|
|
416
423
|
mountedRef.current = true;
|
|
417
424
|
if (!slug) {
|
|
@@ -424,7 +431,7 @@ function useArticle(slug) {
|
|
|
424
431
|
mountedRef.current = false;
|
|
425
432
|
};
|
|
426
433
|
}, [slug, refresh]);
|
|
427
|
-
return { article, isLoading, error, refresh };
|
|
434
|
+
return { article, isLoading, error, refresh, recordView };
|
|
428
435
|
}
|
|
429
436
|
|
|
430
437
|
// src/library/useArticleSearch.ts
|
package/dist/index.d.cts
CHANGED
|
@@ -185,6 +185,8 @@ interface UseArticleReturn {
|
|
|
185
185
|
error: Error | null;
|
|
186
186
|
/** Re-fetch the article. */
|
|
187
187
|
refresh: () => Promise<void>;
|
|
188
|
+
/** Record a view for this article. Call once when the article page mounts. */
|
|
189
|
+
recordView: () => Promise<void>;
|
|
188
190
|
}
|
|
189
191
|
/**
|
|
190
192
|
* Fetch a single article by slug.
|
package/dist/index.d.ts
CHANGED
|
@@ -185,6 +185,8 @@ interface UseArticleReturn {
|
|
|
185
185
|
error: Error | null;
|
|
186
186
|
/** Re-fetch the article. */
|
|
187
187
|
refresh: () => Promise<void>;
|
|
188
|
+
/** Record a view for this article. Call once when the article page mounts. */
|
|
189
|
+
recordView: () => Promise<void>;
|
|
188
190
|
}
|
|
189
191
|
/**
|
|
190
192
|
* Fetch a single article by slug.
|
package/dist/index.js
CHANGED
|
@@ -373,6 +373,13 @@ function useArticle(slug) {
|
|
|
373
373
|
}
|
|
374
374
|
}
|
|
375
375
|
}, [client, slug]);
|
|
376
|
+
const recordView = useCallback7(async () => {
|
|
377
|
+
if (!slug) return;
|
|
378
|
+
try {
|
|
379
|
+
await client.recordView(slug);
|
|
380
|
+
} catch {
|
|
381
|
+
}
|
|
382
|
+
}, [client, slug]);
|
|
376
383
|
useEffect7(() => {
|
|
377
384
|
mountedRef.current = true;
|
|
378
385
|
if (!slug) {
|
|
@@ -385,7 +392,7 @@ function useArticle(slug) {
|
|
|
385
392
|
mountedRef.current = false;
|
|
386
393
|
};
|
|
387
394
|
}, [slug, refresh]);
|
|
388
|
-
return { article, isLoading, error, refresh };
|
|
395
|
+
return { article, isLoading, error, refresh, recordView };
|
|
389
396
|
}
|
|
390
397
|
|
|
391
398
|
// src/library/useArticleSearch.ts
|