react-fate 0.1.1 → 0.1.3
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 +4 -19
- package/lib/index.mjs +1 -1
- package/package.json +19 -18
package/README.md
CHANGED
|
@@ -552,18 +552,9 @@ const PostView = view<Post>()({
|
|
|
552
552
|
Now you can apply the `useListView` hook inside of your `PostCard` component to read the list of comments and load more comments when needed:
|
|
553
553
|
|
|
554
554
|
```tsx
|
|
555
|
-
export function PostCard({
|
|
556
|
-
detail,
|
|
557
|
-
post: postRef,
|
|
558
|
-
}: {
|
|
559
|
-
detail?: boolean;
|
|
560
|
-
post: ViewRef<'Post'>;
|
|
561
|
-
}) {
|
|
555
|
+
export function PostCard({ detail, post: postRef }: { detail?: boolean; post: ViewRef<'Post'> }) {
|
|
562
556
|
const post = useView(PostView, postRef);
|
|
563
|
-
const [comments, loadNext] = useListView(
|
|
564
|
-
CommentConnectionView,
|
|
565
|
-
post.comments,
|
|
566
|
-
);
|
|
557
|
+
const [comments, loadNext] = useListView(CommentConnectionView, post.comments);
|
|
567
558
|
|
|
568
559
|
return (
|
|
569
560
|
<div>
|
|
@@ -615,10 +606,7 @@ If you are not using an async component library, you can use React's `useTransit
|
|
|
615
606
|
const LikeButton = ({ post }: { post: { id: string; likes: number } }) => {
|
|
616
607
|
const fate = useFateClient();
|
|
617
608
|
const [, startTransition] = useTransition();
|
|
618
|
-
const [result, like, isPending] = useActionState(
|
|
619
|
-
fate.actions.post.like,
|
|
620
|
-
null,
|
|
621
|
-
);
|
|
609
|
+
const [result, like, isPending] = useActionState(fate.actions.post.like, null);
|
|
622
610
|
|
|
623
611
|
return (
|
|
624
612
|
<button
|
|
@@ -805,10 +793,7 @@ const [result, like] = useActionState(fate.actions.post.like, null);
|
|
|
805
793
|
useEffect(() => {
|
|
806
794
|
if (result?.error) {
|
|
807
795
|
// Reset the action state after 3 seconds.
|
|
808
|
-
const timeout = setTimeout(
|
|
809
|
-
() => startTransition(() => like('reset')),
|
|
810
|
-
3000,
|
|
811
|
-
);
|
|
796
|
+
const timeout = setTimeout(() => startTransition(() => like('reset')), 3000);
|
|
812
797
|
return () => clearTimeout(timeout);
|
|
813
798
|
}
|
|
814
799
|
}, [like, result]);
|
package/lib/index.mjs
CHANGED
|
@@ -18,7 +18,7 @@ function FateClient({ children, client }) {
|
|
|
18
18
|
*/
|
|
19
19
|
function useFateClient() {
|
|
20
20
|
const context = use(FateContext);
|
|
21
|
-
if (!context) throw new Error(`react-fate: '<
|
|
21
|
+
if (!context) throw new Error(`react-fate: '<FateClient client={fate}>' is missing.`);
|
|
22
22
|
return context;
|
|
23
23
|
}
|
|
24
24
|
|
package/package.json
CHANGED
|
@@ -1,46 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-fate",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "fate is a modern data client for React.",
|
|
5
5
|
"homepage": "https://github.com/nkzw-tech/fate",
|
|
6
|
-
"repository": {
|
|
7
|
-
"type": "git",
|
|
8
|
-
"url": "https://github.com/nkzw-tech/fate"
|
|
9
|
-
},
|
|
10
6
|
"license": "MIT",
|
|
11
7
|
"author": {
|
|
12
8
|
"name": "Christoph Nakazawa",
|
|
13
9
|
"email": "christoph.pojer@gmail.com"
|
|
14
10
|
},
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
"
|
|
18
|
-
"types": "./lib/index.d.mts",
|
|
19
|
-
"default": "./lib/index.mjs"
|
|
20
|
-
}
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/nkzw-tech/fate"
|
|
21
14
|
},
|
|
22
|
-
"main": "./lib/index.mjs",
|
|
23
|
-
"types": "./lib/index.d.mts",
|
|
24
15
|
"bin": {
|
|
25
16
|
"fate": "./lib/cli.mjs"
|
|
26
17
|
},
|
|
27
18
|
"files": [
|
|
28
19
|
"lib"
|
|
29
20
|
],
|
|
21
|
+
"type": "module",
|
|
22
|
+
"main": "./lib/index.mjs",
|
|
23
|
+
"types": "./lib/index.d.mts",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./lib/index.d.mts",
|
|
27
|
+
"@nkzw/source": "./src/index.tsx",
|
|
28
|
+
"default": "./lib/index.mjs"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
30
31
|
"dependencies": {
|
|
31
|
-
"@nkzw/fate": "^0.1.
|
|
32
|
+
"@nkzw/fate": "^0.1.3"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
|
-
"@types/react": "^19.2.
|
|
35
|
+
"@types/react": "^19.2.9",
|
|
35
36
|
"@types/react-dom": "^19.2.3",
|
|
36
|
-
"react": "^19.2.
|
|
37
|
-
"react-dom": "^19.2.
|
|
37
|
+
"react": "^19.2.3",
|
|
38
|
+
"react-dom": "^19.2.3"
|
|
38
39
|
},
|
|
39
40
|
"peerDependencies": {
|
|
40
41
|
"react": "^19.2.0",
|
|
41
42
|
"react-dom": "^19.2.0"
|
|
42
43
|
},
|
|
43
44
|
"scripts": {
|
|
44
|
-
"build": "
|
|
45
|
+
"build": "vite lib -d lib --target=node24 src/index.tsx src/cli.ts"
|
|
45
46
|
}
|
|
46
47
|
}
|