@consentify/react 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Roman Denysov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,82 @@
1
+ # @consentify/react
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@consentify/react.svg)](https://www.npmjs.com/package/@consentify/react)
4
+ [![npm downloads](https://img.shields.io/npm/dm/@consentify/react.svg)](https://www.npmjs.com/package/@consentify/react)
5
+ [![license](https://img.shields.io/npm/l/@consentify/react.svg)](./LICENSE)
6
+
7
+ > React hook for [@consentify/core](https://www.npmjs.com/package/@consentify/core) — headless cookie consent SDK.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ npm install @consentify/react
13
+ # or
14
+ pnpm add @consentify/react
15
+ # or
16
+ yarn add @consentify/react
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ```tsx
22
+ import { createConsentify, defaultCategories, useConsentify } from '@consentify/react';
23
+
24
+ // Create once at module level
25
+ const consent = createConsentify({
26
+ policy: { identifier: 'v1.0', categories: defaultCategories },
27
+ });
28
+
29
+ function CookieBanner() {
30
+ const state = useConsentify(consent);
31
+
32
+ if (state.decision === 'decided') return null;
33
+
34
+ return (
35
+ <div className="cookie-banner">
36
+ <p>We use cookies to enhance your experience.</p>
37
+ <button onClick={() => consent.client.set({
38
+ analytics: true,
39
+ marketing: true,
40
+ preferences: true
41
+ })}>
42
+ Accept All
43
+ </button>
44
+ <button onClick={() => consent.client.set({
45
+ analytics: false,
46
+ marketing: false,
47
+ preferences: false
48
+ })}>
49
+ Essential Only
50
+ </button>
51
+ </div>
52
+ );
53
+ }
54
+ ```
55
+
56
+ ## API
57
+
58
+ ### `useConsentify(instance)`
59
+
60
+ React hook that subscribes to consent state changes using `useSyncExternalStore`.
61
+
62
+ **Parameters:**
63
+ - `instance` — The object returned by `createConsentify()`
64
+
65
+ **Returns:** `ConsentState<T>`
66
+ - `{ decision: 'unset' }` — No consent given yet
67
+ - `{ decision: 'decided', snapshot }` — User has made a choice
68
+
69
+ ### Re-exports
70
+
71
+ This package re-exports everything from `@consentify/core`:
72
+ - `createConsentify`
73
+ - `defaultCategories`
74
+ - All types (`ConsentState`, `Snapshot`, `Choices`, etc.)
75
+
76
+ ## SSR Support
77
+
78
+ The hook uses `useSyncExternalStore` with a server snapshot that returns `{ decision: 'unset' }`, ensuring hydration works correctly in SSR frameworks like Next.js.
79
+
80
+ ## License
81
+
82
+ MIT © 2025 [Roman Denysov](https://github.com/RomanDenysov)
@@ -0,0 +1,11 @@
1
+ import type { ConsentState } from "@consentify/core";
2
+ interface ConsentifyClient<T extends string> {
3
+ subscribe: (callback: () => void) => () => void;
4
+ get: () => ConsentState<T>;
5
+ getServerSnapshot: () => ConsentState<T>;
6
+ }
7
+ interface ConsentifyInstance<T extends string> {
8
+ client: ConsentifyClient<T>;
9
+ }
10
+ export declare function useConsentify<T extends string>(instance: ConsentifyInstance<T>): ConsentState<T>;
11
+ export * from "@consentify/core";
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ "use client";
2
+ import { useSyncExternalStore } from "react";
3
+ export function useConsentify(instance) {
4
+ return useSyncExternalStore(instance.client.subscribe, instance.client.get, instance.client.getServerSnapshot);
5
+ }
6
+ export * from "@consentify/core";
package/package.json ADDED
@@ -0,0 +1,80 @@
1
+ {
2
+ "name": "@consentify/react",
3
+ "version": "1.0.0",
4
+ "description": "React hook for @consentify/core",
5
+ "author": {
6
+ "name": "Roman Denysov",
7
+ "url": "https://github.com/RomanDenysov"
8
+ },
9
+ "funding": [
10
+ {
11
+ "type": "github",
12
+ "url": "https://github.com/sponsors/RomanDenysov"
13
+ },
14
+ {
15
+ "type": "ko-fi",
16
+ "url": "https://ko-fi.com/romandenysov"
17
+ },
18
+ {
19
+ "type": "buymeacoffee",
20
+ "url": "https://buymeacoffee.com/romandenysov"
21
+ }
22
+ ],
23
+ "engines": {
24
+ "node": ">=20.0.0",
25
+ "pnpm": ">=9"
26
+ },
27
+ "keywords": [
28
+ "cookie",
29
+ "consent",
30
+ "gdpr",
31
+ "ccpa",
32
+ "privacy",
33
+ "typescript",
34
+ "react",
35
+ "hooks"
36
+ ],
37
+ "sideEffects": false,
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "git+https://github.com/RomanDenysov/consentify.git",
41
+ "directory": "packages/react"
42
+ },
43
+ "bugs": {
44
+ "url": "https://github.com/RomanDenysov/consentify/issues"
45
+ },
46
+ "homepage": "https://github.com/RomanDenysov/consentify#readme",
47
+ "exports": {
48
+ ".": {
49
+ "import": "./dist/index.js",
50
+ "types": "./dist/index.d.ts"
51
+ }
52
+ },
53
+ "module": "./dist/index.js",
54
+ "types": "./dist/index.d.ts",
55
+ "files": [
56
+ "dist/**/*",
57
+ "README.md",
58
+ "LICENSE"
59
+ ],
60
+ "license": "MIT",
61
+ "type": "module",
62
+ "publishConfig": {
63
+ "access": "public"
64
+ },
65
+ "peerDependencies": {
66
+ "react": "^18.0.0 || ^19.0.0"
67
+ },
68
+ "dependencies": {
69
+ "@consentify/core": "^1.1.0"
70
+ },
71
+ "devDependencies": {
72
+ "@types/react": "^19.0.0",
73
+ "rimraf": "^6.0.0",
74
+ "typescript": "^5.7.0"
75
+ },
76
+ "scripts": {
77
+ "build": "rimraf dist && tsc -p tsconfig.build.json",
78
+ "check": "tsc --noEmit"
79
+ }
80
+ }