@chill-sharp/react-client 1.1.12 → 1.1.15

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/package.json CHANGED
@@ -1,49 +1,49 @@
1
- {
2
- "name": "@chill-sharp/react-client",
3
- "repository": {
4
- "type": "git",
5
- "url": "git+https://github.com/e-500/chill-sharp.git",
6
- "directory": "extra/chill-sharp-react-client"
7
- },
8
- "version": "1.1.12",
9
- "description": "React client helpers for generic ChillSharp services",
10
- "license": "AGPL-3.0-or-later",
11
- "type": "module",
12
- "main": "./dist/index.js",
13
- "types": "./dist/index.d.ts",
14
- "exports": {
15
- ".": {
16
- "types": "./dist/index.d.ts",
17
- "import": "./dist/index.js"
18
- }
19
- },
20
- "files": [
21
- "dist",
22
- "src",
23
- "README.md"
24
- ],
25
- "scripts": {
26
- "build": "tsc -p tsconfig.json",
27
- "check": "tsc -p tsconfig.json --noEmit",
28
- "prepare": "npm run build",
29
- "prepack": "npm run build"
30
- },
31
- "keywords": [
32
- "chillsharp",
33
- "react",
34
- "typescript",
35
- "client",
36
- "hooks"
37
- ],
38
- "author": "Andrea Piovesan",
39
- "peerDependencies": {
40
- "react": "^18.2.0 || ^19.0.0",
41
- "@chill-sharp/ts-client": "^1.1.12"
42
- },
43
- "devDependencies": {
44
- "@types/react": "^19.1.0",
45
- "typescript": "^5.8.2",
46
- "@chill-sharp/ts-client": "file:../chill-sharp-ts-client"
47
- }
48
- }
49
-
1
+ {
2
+ "name": "@chill-sharp/react-client",
3
+ "repository": {
4
+ "type": "git",
5
+ "url": "git+https://github.com/e-500/chill-sharp.git",
6
+ "directory": "extra/chill-sharp-react-client"
7
+ },
8
+ "version": "1.1.15",
9
+ "description": "React client helpers for generic ChillSharp services",
10
+ "license": "AGPL-3.0-or-later",
11
+ "type": "module",
12
+ "main": "./dist/index.js",
13
+ "types": "./dist/index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "import": "./dist/index.js"
18
+ }
19
+ },
20
+ "files": [
21
+ "dist",
22
+ "src",
23
+ "README.md"
24
+ ],
25
+ "scripts": {
26
+ "build": "tsc -p tsconfig.json",
27
+ "check": "tsc -p tsconfig.json --noEmit",
28
+ "prepare": "npm run build",
29
+ "prepack": "npm run build"
30
+ },
31
+ "keywords": [
32
+ "chillsharp",
33
+ "react",
34
+ "typescript",
35
+ "client",
36
+ "hooks"
37
+ ],
38
+ "author": "Andrea Piovesan",
39
+ "peerDependencies": {
40
+ "react": "^18.2.0 || ^19.0.0",
41
+ "@chill-sharp/ts-client": "^1.1.15"
42
+ },
43
+ "devDependencies": {
44
+ "@types/react": "^19.1.0",
45
+ "typescript": "^5.8.2",
46
+ "@chill-sharp/ts-client": "file:../chill-sharp-ts-client"
47
+ }
48
+ }
49
+
package/src/context.tsx CHANGED
@@ -1,58 +1,58 @@
1
- /*
2
- * ChillSharp is a lightweight .NET library that sits on top of Entity Framework Core
3
- * and turns an existing data model into a fully working REST API with almost no setup.
4
- * Copyright (C) 2025 Andrea Piovesan
5
- *
6
- * This program is free software: you can redistribute it and/or modify
7
- * it under the terms of the GNU Affero General Public License as published by
8
- * the Free Software Foundation, either version 3 of the License, or
9
- * (at your option) any later version.
10
- *
11
- * This program is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU Affero General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU Affero General Public License
17
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
18
- */
19
-
20
- import React, { createContext, useContext, useRef } from "react";
21
- import { ChillSharpClient } from "@chill-sharp/ts-client";
22
- import type { ChillSharpClientOptions } from "@chill-sharp/ts-client";
23
-
24
- export interface ChillSharpProviderProps {
25
- baseUrl: string;
26
- client?: ChillSharpClient;
27
- options?: ChillSharpClientOptions;
28
- children: React.ReactNode;
29
- }
30
-
31
- const ChillSharpContext = createContext<ChillSharpClient | null>(null);
32
-
33
- export function ChillSharpProvider(props: ChillSharpProviderProps) {
34
- const clientRef = useRef<ChillSharpClient | null>(props.client ?? null);
35
-
36
- if (props.client && clientRef.current !== props.client) {
37
- clientRef.current = props.client;
38
- }
39
-
40
- if (!clientRef.current) {
41
- clientRef.current = new ChillSharpClient(props.baseUrl, props.options);
42
- }
43
-
44
- return (
45
- <ChillSharpContext.Provider value={clientRef.current}>
46
- {props.children}
47
- </ChillSharpContext.Provider>
48
- );
49
- }
50
-
51
- export function useChillSharpClient(): ChillSharpClient {
52
- const client = useContext(ChillSharpContext);
53
- if (!client) {
54
- throw new Error("useChillSharpClient must be used inside ChillSharpProvider.");
55
- }
56
-
57
- return client;
58
- }
1
+ /*
2
+ * ChillSharp is a lightweight .NET library that sits on top of Entity Framework Core
3
+ * and turns an existing data model into a fully working REST API with almost no setup.
4
+ * Copyright (C) 2025 Andrea Piovesan
5
+ *
6
+ * This program is free software: you can redistribute it and/or modify
7
+ * it under the terms of the GNU Affero General Public License as published by
8
+ * the Free Software Foundation, either version 3 of the License, or
9
+ * (at your option) any later version.
10
+ *
11
+ * This program is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ * GNU Affero General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Affero General Public License
17
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
18
+ */
19
+
20
+ import React, { createContext, useContext, useRef } from "react";
21
+ import { ChillSharpClient } from "@chill-sharp/ts-client";
22
+ import type { ChillSharpClientOptions } from "@chill-sharp/ts-client";
23
+
24
+ export interface ChillSharpProviderProps {
25
+ baseUrl: string;
26
+ client?: ChillSharpClient;
27
+ options?: ChillSharpClientOptions;
28
+ children: React.ReactNode;
29
+ }
30
+
31
+ const ChillSharpContext = createContext<ChillSharpClient | null>(null);
32
+
33
+ export function ChillSharpProvider(props: ChillSharpProviderProps) {
34
+ const clientRef = useRef<ChillSharpClient | null>(props.client ?? null);
35
+
36
+ if (props.client && clientRef.current !== props.client) {
37
+ clientRef.current = props.client;
38
+ }
39
+
40
+ if (!clientRef.current) {
41
+ clientRef.current = new ChillSharpClient(props.baseUrl, props.options);
42
+ }
43
+
44
+ return (
45
+ <ChillSharpContext.Provider value={clientRef.current}>
46
+ {props.children}
47
+ </ChillSharpContext.Provider>
48
+ );
49
+ }
50
+
51
+ export function useChillSharpClient(): ChillSharpClient {
52
+ const client = useContext(ChillSharpContext);
53
+ if (!client) {
54
+ throw new Error("useChillSharpClient must be used inside ChillSharpProvider.");
55
+ }
56
+
57
+ return client;
58
+ }