@virentia/net-react 0.1.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/README.md +32 -0
- package/dist/index.cjs +46 -0
- package/dist/index.d.cts +26 -0
- package/dist/index.d.mts +26 -0
- package/dist/index.mjs +26 -0
- package/package.json +55 -0
package/README.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# @virentia/net-react
|
|
2
|
+
|
|
3
|
+
React bindings for [`@virentia/net-core`](https://movpushmov.dev/net/). A net query is a
|
|
4
|
+
Virentia effect, so these hooks are thin sugar over `@virentia/react`'s `useUnit`.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
pnpm add @virentia/net-react @virentia/net-core @virentia/react @virentia/core react
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
import { ScopeProvider, useQuery, useMutation } from "@virentia/net-react";
|
|
16
|
+
|
|
17
|
+
function User({ id }: { id: string }) {
|
|
18
|
+
const { data, error, pending, run } = useQuery(userQuery);
|
|
19
|
+
useEffect(() => { run({ id }); }, [id]);
|
|
20
|
+
if (pending) return <Spinner />;
|
|
21
|
+
if (error) return <ErrorView />;
|
|
22
|
+
return <Profile user={data} />;
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
`useQuery(query)` → `{ data, error, pending, stale, run, refetch, reset }`.
|
|
27
|
+
`useMutation(mutation)` → `{ data, error, pending, mutate, reset }`.
|
|
28
|
+
Wrap the tree in `ScopeProvider` (re-exported) so state is per-scope.
|
|
29
|
+
|
|
30
|
+
## License
|
|
31
|
+
|
|
32
|
+
MIT © 2026 movpushmov
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let _virentia_react = require("@virentia/react");
|
|
3
|
+
//#region lib/use-query.ts
|
|
4
|
+
function useQuery(query) {
|
|
5
|
+
return (0, _virentia_react.useUnit)({
|
|
6
|
+
data: query.data,
|
|
7
|
+
error: query.error,
|
|
8
|
+
pending: query.pending,
|
|
9
|
+
stale: query.stale,
|
|
10
|
+
run: query,
|
|
11
|
+
refetch: query.refresh,
|
|
12
|
+
reset: query.reset
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region lib/use-mutation.ts
|
|
17
|
+
function useMutation(mutation) {
|
|
18
|
+
return (0, _virentia_react.useUnit)({
|
|
19
|
+
data: mutation.data,
|
|
20
|
+
error: mutation.error,
|
|
21
|
+
pending: mutation.pending,
|
|
22
|
+
mutate: mutation,
|
|
23
|
+
reset: mutation.reset
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
Object.defineProperty(exports, "ScopeProvider", {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
get: function() {
|
|
30
|
+
return _virentia_react.ScopeProvider;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
exports.useMutation = useMutation;
|
|
34
|
+
Object.defineProperty(exports, "useProvidedScope", {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
get: function() {
|
|
37
|
+
return _virentia_react.useProvidedScope;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
exports.useQuery = useQuery;
|
|
41
|
+
Object.defineProperty(exports, "useUnit", {
|
|
42
|
+
enumerable: true,
|
|
43
|
+
get: function() {
|
|
44
|
+
return _virentia_react.useUnit;
|
|
45
|
+
}
|
|
46
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Mutation, Query } from "@virentia/net-core";
|
|
2
|
+
import { ScopeProvider, useProvidedScope, useUnit } from "@virentia/react";
|
|
3
|
+
|
|
4
|
+
//#region lib/use-query.d.ts
|
|
5
|
+
interface UseQueryResult<Raw, Data, Err> {
|
|
6
|
+
data: Data | null;
|
|
7
|
+
error: Err | null;
|
|
8
|
+
pending: boolean;
|
|
9
|
+
stale: boolean;
|
|
10
|
+
run: (params: Raw) => Promise<Data>;
|
|
11
|
+
refetch: () => Promise<void>;
|
|
12
|
+
reset: () => Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
declare function useQuery<Raw, Data, Err>(query: Query<Raw, Data, Err>): UseQueryResult<Raw, Data, Err>;
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region lib/use-mutation.d.ts
|
|
17
|
+
interface UseMutationResult<Raw, Data, Err> {
|
|
18
|
+
data: Data | null;
|
|
19
|
+
error: Err | null;
|
|
20
|
+
pending: boolean;
|
|
21
|
+
mutate: (params: Raw) => Promise<Data>;
|
|
22
|
+
reset: () => Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
declare function useMutation<Raw, Data, Err>(mutation: Mutation<Raw, Data, Err>): UseMutationResult<Raw, Data, Err>;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { ScopeProvider, type UseMutationResult, type UseQueryResult, useMutation, useProvidedScope, useQuery, useUnit };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ScopeProvider, useProvidedScope, useUnit } from "@virentia/react";
|
|
2
|
+
import { Mutation, Query } from "@virentia/net-core";
|
|
3
|
+
|
|
4
|
+
//#region lib/use-query.d.ts
|
|
5
|
+
interface UseQueryResult<Raw, Data, Err> {
|
|
6
|
+
data: Data | null;
|
|
7
|
+
error: Err | null;
|
|
8
|
+
pending: boolean;
|
|
9
|
+
stale: boolean;
|
|
10
|
+
run: (params: Raw) => Promise<Data>;
|
|
11
|
+
refetch: () => Promise<void>;
|
|
12
|
+
reset: () => Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
declare function useQuery<Raw, Data, Err>(query: Query<Raw, Data, Err>): UseQueryResult<Raw, Data, Err>;
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region lib/use-mutation.d.ts
|
|
17
|
+
interface UseMutationResult<Raw, Data, Err> {
|
|
18
|
+
data: Data | null;
|
|
19
|
+
error: Err | null;
|
|
20
|
+
pending: boolean;
|
|
21
|
+
mutate: (params: Raw) => Promise<Data>;
|
|
22
|
+
reset: () => Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
declare function useMutation<Raw, Data, Err>(mutation: Mutation<Raw, Data, Err>): UseMutationResult<Raw, Data, Err>;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { ScopeProvider, type UseMutationResult, type UseQueryResult, useMutation, useProvidedScope, useQuery, useUnit };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ScopeProvider, useProvidedScope, useUnit, useUnit as useUnit$1 } from "@virentia/react";
|
|
2
|
+
//#region lib/use-query.ts
|
|
3
|
+
function useQuery(query) {
|
|
4
|
+
return useUnit$1({
|
|
5
|
+
data: query.data,
|
|
6
|
+
error: query.error,
|
|
7
|
+
pending: query.pending,
|
|
8
|
+
stale: query.stale,
|
|
9
|
+
run: query,
|
|
10
|
+
refetch: query.refresh,
|
|
11
|
+
reset: query.reset
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region lib/use-mutation.ts
|
|
16
|
+
function useMutation(mutation) {
|
|
17
|
+
return useUnit$1({
|
|
18
|
+
data: mutation.data,
|
|
19
|
+
error: mutation.error,
|
|
20
|
+
pending: mutation.pending,
|
|
21
|
+
mutate: mutation,
|
|
22
|
+
reset: mutation.reset
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
export { ScopeProvider, useMutation, useProvidedScope, useQuery, useUnit };
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@virentia/net-react",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"keywords": [],
|
|
6
|
+
"homepage": "https://movpushmov.dev/net/react/",
|
|
7
|
+
"bugs": {
|
|
8
|
+
"url": "https://github.com/virentia-labs/net/issues"
|
|
9
|
+
},
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"author": "movpushmov",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/virentia-labs/net.git",
|
|
15
|
+
"directory": "packages/react"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"type": "module",
|
|
21
|
+
"main": "./dist/index.cjs",
|
|
22
|
+
"module": "./dist/index.mjs",
|
|
23
|
+
"types": "./dist/index.d.mts",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./dist/index.d.mts",
|
|
27
|
+
"import": "./dist/index.mjs",
|
|
28
|
+
"require": "./dist/index.cjs"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@virentia/react": "^0.2.11",
|
|
36
|
+
"@virentia/net-core": "0.1.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@testing-library/react": "^16.3.0",
|
|
40
|
+
"@types/react": "^19.2.7",
|
|
41
|
+
"@virentia/core": "0.6.3",
|
|
42
|
+
"happy-dom": "^20.0.10",
|
|
43
|
+
"react": "^19.2.1",
|
|
44
|
+
"react-dom": "^19.2.1"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"@virentia/core": ">=0.4",
|
|
48
|
+
"react": ">=18"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build": "tsdown",
|
|
52
|
+
"test": "vitest run",
|
|
53
|
+
"test:watch": "vitest"
|
|
54
|
+
}
|
|
55
|
+
}
|