@dif.sh/react 0.5.1 → 0.6.1

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.
Files changed (2) hide show
  1. package/README.md +15 -9
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -11,19 +11,19 @@ directly.
11
11
  npm install @dif.sh/sdk @dif.sh/react
12
12
  ```
13
13
 
14
- `@dif.sh/sdk` is a peer dependency — install it explicitly.
14
+ `@dif.sh/sdk` is a peer dependency, so install it explicitly.
15
15
 
16
16
  ## Initialize at the root of your tree
17
17
 
18
18
  ```tsx
19
19
  import { DifProvider } from "@dif.sh/react";
20
+ import { events } from "@/dif/generated/events"; // cloud config + publishable key
20
21
 
21
22
  export default function RootLayout({ children }: { children: React.ReactNode }) {
22
23
  return (
23
24
  <DifProvider
24
25
  config={{
25
- project: "acme-shop",
26
- publishableKey: process.env.NEXT_PUBLIC_DIF_PUBLISHABLE_KEY,
26
+ events,
27
27
  userId: () => currentUser?.id ?? null,
28
28
  }}
29
29
  >
@@ -33,6 +33,12 @@ export default function RootLayout({ children }: { children: React.ReactNode })
33
33
  }
34
34
  ```
35
35
 
36
+ Connect the project once with `dif connect --key dif_pk_live_…` (or `dif init
37
+ --key …`). The key lands in `dif/config.yaml` and `dif build` bakes it into
38
+ `dif/generated/events.ts`, so there's no `NEXT_PUBLIC_DIF_PUBLISHABLE_KEY` env
39
+ var to wire up. (You can still pass an explicit `publishableKey` in `config` to
40
+ override per environment.)
41
+
36
42
  The provider runs `dif.init(config)` exactly once on first render. The
37
43
  underlying state is a module-level singleton; re-mounting the provider with
38
44
  a different config will replace the previous one.
@@ -68,17 +74,17 @@ export function CheckoutCTA() {
68
74
  ```
69
75
 
70
76
  `exposure` has the same signature as the bare `dif()` from `@dif.sh/sdk`.
71
- You can also keep using the bare import directly in non-component code —
77
+ You can also keep using the bare import directly in non-component code;
72
78
  both paths read the same module-level state set by `<DifProvider>`.
73
79
 
74
80
  ## Preview & QA forcing
75
81
 
76
- `<DifProvider>` reads the `?_dif=` URL param / `_dif` cookie on mount, so anyone
77
- can force a variant by opening a link — `?_dif=checkout-cta-v2=variant_a`
82
+ `<DifProvider>` reads the `?_dif=` URL param / `_dif` cookie on mount, so
83
+ anyone can force a variant by opening a link: `?_dif=checkout-cta-v2=variant_a`
78
84
  (`?_dif=off` clears). A forced assignment **never fires an exposure**, and a
79
85
  small preview badge shows the active forces. Disable per-env with
80
- `allowOverrides={false}`, or hide the badge with `preview={false}`. Generate the
81
- link with `npx dif qa --force <exp>=<variant> --preview-url <url>`.
86
+ `allowOverrides={false}`, or hide the badge with `preview={false}`. Generate
87
+ the link with `dif qa --force <exp>=<variant> --preview-url <url>`.
82
88
 
83
89
  ## What this package does, what it doesn't
84
90
 
@@ -87,7 +93,7 @@ link with `npx dif qa --force <exp>=<variant> --preview-url <url>`.
87
93
  - Provide `useDif()` to read `{ track, exposure }` from anywhere.
88
94
 
89
95
  **Does not:**
90
- - Re-initialize on prop changes in v0 — pass a stable config.
96
+ - Re-initialize on prop changes in v0; pass a stable config.
91
97
  - Maintain its own event queue. Same fire-and-forget semantics as the SDK.
92
98
 
93
99
  See [../sdk/README.md](../sdk/README.md) for the full SDK contract.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dif.sh/react",
3
- "version": "0.5.1",
3
+ "version": "0.6.1",
4
4
  "description": "React adapter for @dif.sh/sdk — provider + useDif hook.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -43,7 +43,7 @@
43
43
  "dif.sh"
44
44
  ],
45
45
  "peerDependencies": {
46
- "@dif.sh/sdk": "^0.5.0",
46
+ "@dif.sh/sdk": "^0.6.1",
47
47
  "react": ">=18"
48
48
  },
49
49
  "devDependencies": {