@knocklabs/react-core 0.6.15 → 0.7.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.7.1
4
+
5
+ ### Patch Changes
6
+
7
+ - aa16c97: fix: make the user prop to KnockProvider stable by comparing equality, and prevent re-instantiating the knock client unnecessarily
8
+
9
+ ## 0.7.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 2a0b3e2: Adds support for inline user `identify` calls when authenticating a user via the Knock client.
14
+ You can now pass a `user` object, for example `{ id: "123" }`, directly to the `authenticate` function.
15
+ Additional properties can also be included to update the user record, such as `{ id: "123", name: "Knock" }`.
16
+
17
+ This update also applies to `KnockProvider`, where you can now pass a `user` prop instead of a `userId` prop to achieve the same behavior.
18
+
19
+ ### Patch Changes
20
+
21
+ - Updated dependencies [2a0b3e2]
22
+ - @knocklabs/client@0.15.0
23
+
3
24
  ## 0.6.15
4
25
 
5
26
  ### Patch Changes
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react"),b=require("../../i18n/context/KnockI18nProvider.js"),K=require("../hooks/useAuthenticatedKnockClient.js");require("fast-deep-equal");function m(e){if(e&&typeof e=="object"&&"default"in e)return e;const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:()=>e[t]})}}return n.default=e,Object.freeze(n)}const o=m(f),i=o.createContext(null),P=({apiKey:e,host:n,logLevel:t,userId:r,userToken:s,onUserTokenExpiring:c,timeBeforeExpirationInMs:u,children:a,i18n:l})=>{const d=o.useMemo(()=>({host:n,onUserTokenExpiring:c,timeBeforeExpirationInMs:u,logLevel:t}),[n,c,u,t]),k=K(e??"",r,s,d);return o.createElement(i.Provider,{value:{knock:k}},o.createElement(b.KnockI18nProvider,{i18n:l},a))},p=()=>{const e=o.useContext(i);if(!e)throw new Error("useKnockClient must be used within a KnockProvider");return e.knock};exports.KnockProvider=P;exports.useKnockClient=p;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("react"),K=require("../../i18n/context/KnockI18nProvider.js"),P=require("../hooks/useAuthenticatedKnockClient.js");require("fast-deep-equal");function m(e){if(e&&typeof e=="object"&&"default"in e)return e;const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,o.get?o:{enumerable:!0,get:()=>e[t]})}}return n.default=e,Object.freeze(n)}const r=m(b),a=r.createContext(null),v=({apiKey:e,host:n,logLevel:t,userToken:o,onUserTokenExpiring:u,timeBeforeExpirationInMs:i,children:s,i18n:l,...c})=>{const d=(c==null?void 0:c.user)||(c==null?void 0:c.userId),k=r.useMemo(()=>({host:n,onUserTokenExpiring:u,timeBeforeExpirationInMs:i,logLevel:t}),[n,u,i,t]),f=P(e??"",d,o,k);return r.createElement(a.Provider,{value:{knock:f}},r.createElement(K.KnockI18nProvider,{i18n:l},s))},C=()=>{const e=r.useContext(a);if(!e)throw new Error("useKnockClient must be used within a KnockProvider");return e.knock};exports.KnockProvider=v;exports.useKnockClient=C;
2
2
  //# sourceMappingURL=KnockProvider.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"KnockProvider.js","sources":["../../../../../src/modules/core/context/KnockProvider.tsx"],"sourcesContent":["import Knock, { AuthenticateOptions, LogLevel } from \"@knocklabs/client\";\nimport * as React from \"react\";\nimport { PropsWithChildren } from \"react\";\n\nimport { I18nContent, KnockI18nProvider } from \"../../i18n\";\nimport { useAuthenticatedKnockClient } from \"../hooks\";\n\nexport interface KnockProviderState {\n knock: Knock;\n}\n\nconst KnockContext = React.createContext<KnockProviderState | null>(null);\n\nexport interface KnockProviderProps {\n // Knock client props\n apiKey: string | undefined;\n host?: string;\n // Authentication props\n userId: Knock[\"userId\"];\n userToken?: Knock[\"userToken\"];\n onUserTokenExpiring?: AuthenticateOptions[\"onUserTokenExpiring\"];\n timeBeforeExpirationInMs?: AuthenticateOptions[\"timeBeforeExpirationInMs\"];\n // i18n translations\n i18n?: I18nContent;\n logLevel?: LogLevel;\n}\n\nexport const KnockProvider: React.FC<PropsWithChildren<KnockProviderProps>> = ({\n apiKey,\n host,\n logLevel,\n userId,\n userToken,\n onUserTokenExpiring,\n timeBeforeExpirationInMs,\n children,\n i18n,\n}) => {\n // We memoize the options here so that we don't create a new object on every re-render\n const authenticateOptions = React.useMemo(\n () => ({\n host,\n onUserTokenExpiring,\n timeBeforeExpirationInMs,\n logLevel,\n }),\n [host, onUserTokenExpiring, timeBeforeExpirationInMs, logLevel],\n );\n\n const knock = useAuthenticatedKnockClient(\n apiKey ?? \"\",\n userId,\n userToken,\n authenticateOptions,\n );\n\n return (\n <KnockContext.Provider value={{ knock }}>\n <KnockI18nProvider i18n={i18n}>{children}</KnockI18nProvider>\n </KnockContext.Provider>\n );\n};\n\nexport const useKnockClient = (): Knock => {\n const context = React.useContext(KnockContext);\n if (!context) {\n throw new Error(\"useKnockClient must be used within a KnockProvider\");\n }\n return context.knock;\n};\n"],"names":["KnockContext","React","createContext","KnockProvider","apiKey","host","logLevel","userId","userToken","onUserTokenExpiring","timeBeforeExpirationInMs","children","i18n","authenticateOptions","useMemo","knock","useAuthenticatedKnockClient","KnockI18nProvider","useKnockClient","context","useContext","Error"],"mappings":"yjBAWMA,EAAeC,EAAMC,cAAyC,IAAI,EAgB3DC,EAAiEA,CAAC,CAC7EC,OAAAA,EACAC,KAAAA,EACAC,SAAAA,EACAC,OAAAA,EACAC,UAAAA,EACAC,oBAAAA,EACAC,yBAAAA,EACAC,SAAAA,EACAC,KAAAA,CACF,IAAM,CAEEC,MAAAA,EAAsBZ,EAAMa,QAChC,KAAO,CACLT,KAAAA,EACAI,oBAAAA,EACAC,yBAAAA,EACAJ,SAAAA,IAEF,CAACD,EAAMI,EAAqBC,EAA0BJ,CAAQ,CAChE,EAEMS,EAAQC,EACZZ,GAAU,GACVG,EACAC,EACAK,CACF,EAEA,OACGZ,EAAA,cAAAD,EAAa,SAAb,CAAsB,MAAO,CAAEe,MAAAA,CAAAA,CAC9B,EAAAd,EAAA,cAACgB,EAAAA,kBAAkB,CAAA,KAAAL,CAAA,EAAaD,CAAS,CAC3C,CAEJ,EAEaO,EAAiBA,IAAa,CACnCC,MAAAA,EAAUlB,EAAMmB,WAAWpB,CAAY,EAC7C,GAAI,CAACmB,EACG,MAAA,IAAIE,MAAM,oDAAoD,EAEtE,OAAOF,EAAQJ,KACjB"}
1
+ {"version":3,"file":"KnockProvider.js","sources":["../../../../../src/modules/core/context/KnockProvider.tsx"],"sourcesContent":["import Knock, {\n AuthenticateOptions,\n LogLevel,\n UserWithProperties,\n} from \"@knocklabs/client\";\nimport * as React from \"react\";\nimport { PropsWithChildren } from \"react\";\n\nimport { I18nContent, KnockI18nProvider } from \"../../i18n\";\nimport { useAuthenticatedKnockClient } from \"../hooks\";\n\nexport interface KnockProviderState {\n knock: Knock;\n}\n\nconst KnockContext = React.createContext<KnockProviderState | null>(null);\n\nexport type KnockProviderProps = {\n // Knock client props\n apiKey: string | undefined;\n host?: string;\n userToken?: Knock[\"userToken\"];\n onUserTokenExpiring?: AuthenticateOptions[\"onUserTokenExpiring\"];\n timeBeforeExpirationInMs?: AuthenticateOptions[\"timeBeforeExpirationInMs\"];\n // i18n translations\n i18n?: I18nContent;\n logLevel?: LogLevel;\n} & (\n | {\n /**\n * @deprecated The `userId` prop is deprecated and will be removed in a future version.\n * Please pass the `user` prop instead containing an `id` value.\n * example:\n * ```ts\n * <KnockProvider user={{ id: \"user_123\" }}></KnockProvider>\n * ```\n */\n userId: Knock[\"userId\"];\n user?: never;\n }\n | {\n user: UserWithProperties;\n /**\n * @deprecated The `userId` prop is deprecated and will be removed in a future version.\n * Please pass the `user` prop instead containing an `id` value.\n * example:\n * ```ts\n * <KnockProvider user={{ id: \"user_123\" }}></KnockProvider>\n * ```\n */\n userId?: never;\n }\n);\n\nexport const KnockProvider: React.FC<PropsWithChildren<KnockProviderProps>> = ({\n apiKey,\n host,\n logLevel,\n userToken,\n onUserTokenExpiring,\n timeBeforeExpirationInMs,\n children,\n i18n,\n ...props\n}) => {\n const userIdOrUserWithProperties = props?.user || props?.userId;\n\n // We memoize the options here so that we don't create a new object on every re-render\n const authenticateOptions = React.useMemo(\n () => ({\n host,\n onUserTokenExpiring,\n timeBeforeExpirationInMs,\n logLevel,\n }),\n [host, onUserTokenExpiring, timeBeforeExpirationInMs, logLevel],\n );\n\n const knock = useAuthenticatedKnockClient(\n apiKey ?? \"\",\n userIdOrUserWithProperties,\n userToken,\n authenticateOptions,\n );\n\n return (\n <KnockContext.Provider value={{ knock }}>\n <KnockI18nProvider i18n={i18n}>{children}</KnockI18nProvider>\n </KnockContext.Provider>\n );\n};\n\nexport const useKnockClient = (): Knock => {\n const context = React.useContext(KnockContext);\n if (!context) {\n throw new Error(\"useKnockClient must be used within a KnockProvider\");\n }\n return context.knock;\n};\n"],"names":["KnockContext","React","createContext","KnockProvider","apiKey","host","logLevel","userToken","onUserTokenExpiring","timeBeforeExpirationInMs","children","i18n","props","userIdOrUserWithProperties","user","userId","authenticateOptions","useMemo","knock","useAuthenticatedKnockClient","KnockI18nProvider","useKnockClient","context","useContext","Error"],"mappings":"yjBAeMA,EAAeC,EAAMC,cAAyC,IAAI,EAuC3DC,EAAiEA,CAAC,CAC7EC,OAAAA,EACAC,KAAAA,EACAC,SAAAA,EACAC,UAAAA,EACAC,oBAAAA,EACAC,yBAAAA,EACAC,SAAAA,EACAC,KAAAA,EACA,GAAGC,CACL,IAAM,CACEC,MAAAA,GAA6BD,GAAAA,YAAAA,EAAOE,QAAQF,GAAAA,YAAAA,EAAOG,QAGnDC,EAAsBf,EAAMgB,QAChC,KAAO,CACLZ,KAAAA,EACAG,oBAAAA,EACAC,yBAAAA,EACAH,SAAAA,IAEF,CAACD,EAAMG,EAAqBC,EAA0BH,CAAQ,CAChE,EAEMY,EAAQC,EACZf,GAAU,GACVS,EACAN,EACAS,CACF,EAEA,OACGf,EAAA,cAAAD,EAAa,SAAb,CAAsB,MAAO,CAAEkB,MAAAA,CAAAA,CAC9B,EAAAjB,EAAA,cAACmB,EAAAA,kBAAkB,CAAA,KAAAT,CAAA,EAAaD,CAAS,CAC3C,CAEJ,EAEaW,EAAiBA,IAAa,CACnCC,MAAAA,EAAUrB,EAAMsB,WAAWvB,CAAY,EAC7C,GAAI,CAACsB,EACG,MAAA,IAAIE,MAAM,oDAAoD,EAEtE,OAAOF,EAAQJ,KACjB"}
@@ -1,2 +1,2 @@
1
- "use strict";const s=require("@knocklabs/client"),d=require("react");require("../context/KnockProvider.js");const k=require("./useStableOptions.js");require("date-fns");const l=e=>e&&typeof e=="object"&&"default"in e?e:{default:e},h=l(s),o=l(d);function f(e,r,c,t={}){e.authenticate(r,c,{onUserTokenExpiring:t==null?void 0:t.onUserTokenExpiring,timeBeforeExpirationInMs:t==null?void 0:t.timeBeforeExpirationInMs})}function q(e,r,c,t={}){const a=o.default.useRef(),u=k(t);return o.default.useMemo(()=>{const n=a.current;if(n&&n.isAuthenticated()&&(n.userId!==r||n.userToken!==c))return f(n,r,c,u),n;n&&n.teardown();const i=new h.default(e,{host:u.host,logLevel:u.logLevel});return f(i,r,c,u),a.current=i,i},[e,r,c,u])}module.exports=q;
1
+ "use strict";const h=require("@knocklabs/client"),g=require("react");require("../context/KnockProvider.js");const s=require("./useStableOptions.js");require("date-fns");const d=e=>e&&typeof e=="object"&&"default"in e?e:{default:e},q=d(h),f=d(g);function l(e,i,c,t={}){e.authenticate(i,c,{onUserTokenExpiring:t==null?void 0:t.onUserTokenExpiring,timeBeforeExpirationInMs:t==null?void 0:t.timeBeforeExpirationInMs})}function x(e,i,c,t={}){const a=f.default.useRef(void 0),u=s(t),n=s(i);return f.default.useMemo(()=>{const k=typeof n=="string"?n:n==null?void 0:n.id,r=a.current;if(r&&r.isAuthenticated()&&(r.userId!==k||r.userToken!==c))return l(r,n,c,u),r;r&&r.teardown();const o=new q.default(e,{host:u.host,logLevel:u.logLevel});return l(o,n,c,u),a.current=o,o},[e,n,c,u])}module.exports=x;
2
2
  //# sourceMappingURL=useAuthenticatedKnockClient.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useAuthenticatedKnockClient.js","sources":["../../../../../src/modules/core/hooks/useAuthenticatedKnockClient.ts"],"sourcesContent":["import Knock, { AuthenticateOptions, KnockOptions } from \"@knocklabs/client\";\nimport React from \"react\";\n\nimport { useStableOptions } from \"../../core\";\n\nfunction authenticateWithOptions(\n knock: Knock,\n userId: Knock[\"userId\"],\n userToken?: Knock[\"userToken\"],\n options: AuthenticateOptions = {},\n) {\n knock.authenticate(userId, userToken, {\n onUserTokenExpiring: options?.onUserTokenExpiring,\n timeBeforeExpirationInMs: options?.timeBeforeExpirationInMs,\n });\n}\n\nexport type AuthenticatedKnockClientOptions = KnockOptions &\n AuthenticateOptions;\n\nfunction useAuthenticatedKnockClient(\n apiKey: string,\n userId: Knock[\"userId\"],\n userToken?: Knock[\"userToken\"],\n options: AuthenticatedKnockClientOptions = {},\n) {\n const knockRef = React.useRef<Knock | undefined>();\n const stableOptions = useStableOptions(options);\n\n return React.useMemo(() => {\n const currentKnock = knockRef.current;\n\n // If the userId and the userToken changes then just reauth\n if (\n currentKnock &&\n currentKnock.isAuthenticated() &&\n (currentKnock.userId !== userId || currentKnock.userToken !== userToken)\n ) {\n authenticateWithOptions(currentKnock, userId, userToken, stableOptions);\n return currentKnock;\n }\n\n if (currentKnock) {\n currentKnock.teardown();\n }\n\n // Otherwise instantiate a new Knock client\n const knock = new Knock(apiKey, {\n host: stableOptions.host,\n logLevel: stableOptions.logLevel,\n });\n\n authenticateWithOptions(knock, userId, userToken, stableOptions);\n knockRef.current = knock;\n\n return knock;\n }, [apiKey, userId, userToken, stableOptions]);\n}\n\nexport default useAuthenticatedKnockClient;\n"],"names":["authenticateWithOptions","knock","userId","userToken","options","authenticate","onUserTokenExpiring","timeBeforeExpirationInMs","useAuthenticatedKnockClient","apiKey","knockRef","React","useRef","stableOptions","useStableOptions","useMemo","currentKnock","current","isAuthenticated","teardown","Knock","host","logLevel"],"mappings":"qPAKA,SAASA,EACPC,EACAC,EACAC,EACAC,EAA+B,CAAA,EAC/B,CACMC,EAAAA,aAAaH,EAAQC,EAAW,CACpCG,oBAAqBF,GAAAA,YAAAA,EAASE,oBAC9BC,yBAA0BH,GAAAA,YAAAA,EAASG,wBAAAA,CACpC,CACH,CAKA,SAASC,EACPC,EACAP,EACAC,EACAC,EAA2C,CAAA,EAC3C,CACMM,MAAAA,EAAWC,UAAMC,OAA0B,EAC3CC,EAAgBC,EAAiBV,CAAO,EAEvCO,OAAAA,EAAAA,QAAMI,QAAQ,IAAM,CACzB,MAAMC,EAAeN,EAASO,QAI5BD,GAAAA,GACAA,EAAaE,gBAAgB,IAC5BF,EAAad,SAAWA,GAAUc,EAAab,YAAcA,GAEtCa,OAAAA,EAAAA,EAAcd,EAAQC,EAAWU,CAAa,EAC/DG,EAGLA,GACFA,EAAaG,SAAS,EAIlBlB,MAAAA,EAAQ,IAAImB,EAAAA,QAAMX,EAAQ,CAC9BY,KAAMR,EAAcQ,KACpBC,SAAUT,EAAcS,QAAAA,CACzB,EAEuBrB,OAAAA,EAAAA,EAAOC,EAAQC,EAAWU,CAAa,EAC/DH,EAASO,QAAUhB,EAEZA,GACN,CAACQ,EAAQP,EAAQC,EAAWU,CAAa,CAAC,CAC/C"}
1
+ {"version":3,"file":"useAuthenticatedKnockClient.js","sources":["../../../../../src/modules/core/hooks/useAuthenticatedKnockClient.ts"],"sourcesContent":["import Knock, {\n AuthenticateOptions,\n KnockOptions,\n UserId,\n UserIdOrUserWithProperties,\n} from \"@knocklabs/client\";\nimport React from \"react\";\n\nimport { useStableOptions } from \"../../core\";\n\nfunction authenticateWithOptions(\n knock: Knock,\n userIdOrUserWithProperties: UserIdOrUserWithProperties,\n userToken?: Knock[\"userToken\"],\n options: AuthenticateOptions = {},\n) {\n knock.authenticate(userIdOrUserWithProperties, userToken, {\n onUserTokenExpiring: options?.onUserTokenExpiring,\n timeBeforeExpirationInMs: options?.timeBeforeExpirationInMs,\n });\n}\n\nexport type AuthenticatedKnockClientOptions = KnockOptions &\n AuthenticateOptions;\n\n/**\n * @deprecated Passing `userId` as a `string` is deprecated and will be removed in a future version.\n * Please pass a `user` object instead containing an `id` value.\n * example:\n * ```ts\n * useAuthenticatedKnockClient(\"pk_test_12345\", { id: \"user_123\" });\n * ```\n */\nfunction useAuthenticatedKnockClient(\n apiKey: string,\n userIdOrUserWithProperties: UserId,\n userToken?: Knock[\"userToken\"],\n options?: AuthenticatedKnockClientOptions,\n): Knock;\nfunction useAuthenticatedKnockClient(\n apiKey: string,\n userIdOrUserWithProperties: UserIdOrUserWithProperties,\n userToken?: Knock[\"userToken\"],\n options?: AuthenticatedKnockClientOptions,\n): Knock;\nfunction useAuthenticatedKnockClient(\n apiKey: string,\n userIdOrUserWithProperties: UserIdOrUserWithProperties,\n userToken?: Knock[\"userToken\"],\n options: AuthenticatedKnockClientOptions = {},\n) {\n const knockRef = React.useRef<Knock | undefined>(undefined);\n\n const stableOptions = useStableOptions(options);\n const stableUserIdOrObject = useStableOptions(userIdOrUserWithProperties);\n\n return React.useMemo(() => {\n const userId =\n typeof stableUserIdOrObject === \"string\"\n ? stableUserIdOrObject\n : stableUserIdOrObject?.id;\n\n const currentKnock = knockRef.current;\n\n // If the userId and the userToken changes then just reauth\n if (\n currentKnock &&\n currentKnock.isAuthenticated() &&\n (currentKnock.userId !== userId || currentKnock.userToken !== userToken)\n ) {\n authenticateWithOptions(\n currentKnock,\n stableUserIdOrObject,\n userToken,\n stableOptions,\n );\n return currentKnock;\n }\n\n if (currentKnock) {\n currentKnock.teardown();\n }\n\n // Otherwise instantiate a new Knock client\n const knock = new Knock(apiKey, {\n host: stableOptions.host,\n logLevel: stableOptions.logLevel,\n });\n\n authenticateWithOptions(\n knock,\n stableUserIdOrObject,\n userToken,\n stableOptions,\n );\n knockRef.current = knock;\n\n return knock;\n }, [apiKey, stableUserIdOrObject, userToken, stableOptions]);\n}\n\nexport default useAuthenticatedKnockClient;\n"],"names":["authenticateWithOptions","knock","userIdOrUserWithProperties","userToken","options","authenticate","onUserTokenExpiring","timeBeforeExpirationInMs","useAuthenticatedKnockClient","apiKey","knockRef","React","useRef","undefined","stableOptions","useStableOptions","stableUserIdOrObject","useMemo","userId","id","currentKnock","current","isAuthenticated","teardown","Knock","host","logLevel"],"mappings":"qPAUA,SAASA,EACPC,EACAC,EACAC,EACAC,EAA+B,CAAA,EAC/B,CACMC,EAAAA,aAAaH,EAA4BC,EAAW,CACxDG,oBAAqBF,GAAAA,YAAAA,EAASE,oBAC9BC,yBAA0BH,GAAAA,YAAAA,EAASG,wBAAAA,CACpC,CACH,CAyBA,SAASC,EACPC,EACAP,EACAC,EACAC,EAA2C,CAAA,EAC3C,CACMM,MAAAA,EAAWC,EAAAA,QAAMC,OAA0BC,MAAS,EAEpDC,EAAgBC,EAAiBX,CAAO,EACxCY,EAAuBD,EAAiBb,CAA0B,EAEjES,OAAAA,EAAAA,QAAMM,QAAQ,IAAM,CACzB,MAAMC,EACJ,OAAOF,GAAyB,SAC5BA,EACAA,GAAAA,YAAAA,EAAsBG,GAEtBC,EAAeV,EAASW,QAI5BD,GAAAA,GACAA,EAAaE,gBAAgB,IAC5BF,EAAaF,SAAWA,GAAUE,EAAajB,YAAcA,GAG5DiB,OAAAA,EAAAA,EACAJ,EACAb,EACAW,CACF,EACOM,EAGLA,GACFA,EAAaG,SAAS,EAIlBtB,MAAAA,EAAQ,IAAIuB,EAAAA,QAAMf,EAAQ,CAC9BgB,KAAMX,EAAcW,KACpBC,SAAUZ,EAAcY,QAAAA,CACzB,EAGCzB,OAAAA,EAAAA,EACAe,EACAb,EACAW,CACF,EACAJ,EAASW,QAAUpB,EAEZA,GACN,CAACQ,EAAQO,EAAsBb,EAAWW,CAAa,CAAC,CAC7D"}
@@ -1,2 +1,2 @@
1
- "use strict";const n=require("fast-deep-equal"),r=require("react"),s=t=>t&&typeof t=="object"&&"default"in t?t:{default:t},c=s(n);function a(t){const u=r.useRef();return r.useMemo(()=>{const e=u.current;return e&&c.default(t,e)?e:(u.current=t,t)},[t])}module.exports=a;
1
+ "use strict";const n=require("fast-deep-equal"),r=require("react"),s=t=>t&&typeof t=="object"&&"default"in t?t:{default:t},c=s(n);function a(t){const u=r.useRef(void 0);return r.useMemo(()=>{const e=u.current;return e&&c.default(t,e)?e:(u.current=t,t)},[t])}module.exports=a;
2
2
  //# sourceMappingURL=useStableOptions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useStableOptions.js","sources":["../../../../../src/modules/core/hooks/useStableOptions.ts"],"sourcesContent":["import fastDeepEqual from \"fast-deep-equal\";\nimport { useMemo, useRef } from \"react\";\n\nexport default function useStableOptions<T>(options: T): T {\n const optionsRef = useRef<T>();\n\n return useMemo(() => {\n const currentOptions = optionsRef.current;\n\n if (currentOptions && fastDeepEqual(options, currentOptions)) {\n return currentOptions;\n }\n\n optionsRef.current = options;\n return options;\n }, [options]);\n}\n"],"names":["useStableOptions","options","optionsRef","useRef","useMemo","currentOptions","current","fastDeepEqual"],"mappings":"kIAGA,SAAwBA,EAAoBC,EAAe,CACzD,MAAMC,EAAaC,EAAAA,OAAU,EAE7B,OAAOC,UAAQ,IAAM,CACnB,MAAMC,EAAiBH,EAAWI,QAElC,OAAID,GAAkBE,EAAAA,QAAcN,EAASI,CAAc,EAClDA,GAGTH,EAAWI,QAAUL,EACdA,EAAAA,EACN,CAACA,CAAO,CAAC,CACd"}
1
+ {"version":3,"file":"useStableOptions.js","sources":["../../../../../src/modules/core/hooks/useStableOptions.ts"],"sourcesContent":["import fastDeepEqual from \"fast-deep-equal\";\nimport { useMemo, useRef } from \"react\";\n\nexport default function useStableOptions<T>(options: T): T {\n const optionsRef = useRef<T>(undefined);\n\n return useMemo(() => {\n const currentOptions = optionsRef.current;\n\n if (currentOptions && fastDeepEqual(options, currentOptions)) {\n return currentOptions;\n }\n\n optionsRef.current = options;\n return options;\n }, [options]);\n}\n"],"names":["useStableOptions","options","optionsRef","useRef","undefined","useMemo","currentOptions","current","fastDeepEqual"],"mappings":"kIAGA,SAAwBA,EAAoBC,EAAe,CACnDC,MAAAA,EAAaC,SAAUC,MAAS,EAEtC,OAAOC,UAAQ,IAAM,CACnB,MAAMC,EAAiBJ,EAAWK,QAElC,OAAID,GAAkBE,EAAAA,QAAcP,EAASK,CAAc,EAClDA,GAGTJ,EAAWK,QAAUN,EACdA,EAAAA,EACN,CAACA,CAAO,CAAC,CACd"}
@@ -1,35 +1,35 @@
1
- import * as t from "react";
2
- import { KnockI18nProvider as d } from "../../i18n/context/KnockI18nProvider.mjs";
3
- import l from "../hooks/useAuthenticatedKnockClient.mjs";
1
+ import * as e from "react";
2
+ import { KnockI18nProvider as l } from "../../i18n/context/KnockI18nProvider.mjs";
3
+ import C from "../hooks/useAuthenticatedKnockClient.mjs";
4
4
  import "fast-deep-equal";
5
- const u = t.createContext(null), P = ({
6
- apiKey: e,
7
- host: o,
8
- logLevel: n,
9
- userId: i,
10
- userToken: s,
5
+ const i = e.createContext(null), f = ({
6
+ apiKey: n,
7
+ host: c,
8
+ logLevel: o,
9
+ userToken: k,
11
10
  onUserTokenExpiring: r,
12
- timeBeforeExpirationInMs: c,
13
- children: k,
14
- i18n: m
11
+ timeBeforeExpirationInMs: u,
12
+ children: m,
13
+ i18n: a,
14
+ ...t
15
15
  }) => {
16
- const a = t.useMemo(() => ({
17
- host: o,
16
+ const s = (t == null ? void 0 : t.user) || (t == null ? void 0 : t.userId), d = e.useMemo(() => ({
17
+ host: c,
18
18
  onUserTokenExpiring: r,
19
- timeBeforeExpirationInMs: c,
20
- logLevel: n
21
- }), [o, r, c, n]), K = l(e ?? "", i, s, a);
22
- return /* @__PURE__ */ t.createElement(u.Provider, { value: {
19
+ timeBeforeExpirationInMs: u,
20
+ logLevel: o
21
+ }), [c, r, u, o]), K = C(n ?? "", s, k, d);
22
+ return /* @__PURE__ */ e.createElement(i.Provider, { value: {
23
23
  knock: K
24
- } }, /* @__PURE__ */ t.createElement(d, { i18n: m }, k));
25
- }, f = () => {
26
- const e = t.useContext(u);
27
- if (!e)
24
+ } }, /* @__PURE__ */ e.createElement(l, { i18n: a }, m));
25
+ }, w = () => {
26
+ const n = e.useContext(i);
27
+ if (!n)
28
28
  throw new Error("useKnockClient must be used within a KnockProvider");
29
- return e.knock;
29
+ return n.knock;
30
30
  };
31
31
  export {
32
- P as KnockProvider,
33
- f as useKnockClient
32
+ f as KnockProvider,
33
+ w as useKnockClient
34
34
  };
35
35
  //# sourceMappingURL=KnockProvider.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"KnockProvider.mjs","sources":["../../../../../src/modules/core/context/KnockProvider.tsx"],"sourcesContent":["import Knock, { AuthenticateOptions, LogLevel } from \"@knocklabs/client\";\nimport * as React from \"react\";\nimport { PropsWithChildren } from \"react\";\n\nimport { I18nContent, KnockI18nProvider } from \"../../i18n\";\nimport { useAuthenticatedKnockClient } from \"../hooks\";\n\nexport interface KnockProviderState {\n knock: Knock;\n}\n\nconst KnockContext = React.createContext<KnockProviderState | null>(null);\n\nexport interface KnockProviderProps {\n // Knock client props\n apiKey: string | undefined;\n host?: string;\n // Authentication props\n userId: Knock[\"userId\"];\n userToken?: Knock[\"userToken\"];\n onUserTokenExpiring?: AuthenticateOptions[\"onUserTokenExpiring\"];\n timeBeforeExpirationInMs?: AuthenticateOptions[\"timeBeforeExpirationInMs\"];\n // i18n translations\n i18n?: I18nContent;\n logLevel?: LogLevel;\n}\n\nexport const KnockProvider: React.FC<PropsWithChildren<KnockProviderProps>> = ({\n apiKey,\n host,\n logLevel,\n userId,\n userToken,\n onUserTokenExpiring,\n timeBeforeExpirationInMs,\n children,\n i18n,\n}) => {\n // We memoize the options here so that we don't create a new object on every re-render\n const authenticateOptions = React.useMemo(\n () => ({\n host,\n onUserTokenExpiring,\n timeBeforeExpirationInMs,\n logLevel,\n }),\n [host, onUserTokenExpiring, timeBeforeExpirationInMs, logLevel],\n );\n\n const knock = useAuthenticatedKnockClient(\n apiKey ?? \"\",\n userId,\n userToken,\n authenticateOptions,\n );\n\n return (\n <KnockContext.Provider value={{ knock }}>\n <KnockI18nProvider i18n={i18n}>{children}</KnockI18nProvider>\n </KnockContext.Provider>\n );\n};\n\nexport const useKnockClient = (): Knock => {\n const context = React.useContext(KnockContext);\n if (!context) {\n throw new Error(\"useKnockClient must be used within a KnockProvider\");\n }\n return context.knock;\n};\n"],"names":["KnockContext","React","createContext","KnockProvider","apiKey","host","logLevel","userId","userToken","onUserTokenExpiring","timeBeforeExpirationInMs","children","i18n","authenticateOptions","useMemo","knock","useAuthenticatedKnockClient","KnockI18nProvider","useKnockClient","context","useContext","Error"],"mappings":";;;;AAWA,MAAMA,IAAeC,EAAMC,cAAyC,IAAI,GAgB3DC,IAAiEA,CAAC;AAAA,EAC7EC,QAAAA;AAAAA,EACAC,MAAAA;AAAAA,EACAC,UAAAA;AAAAA,EACAC,QAAAA;AAAAA,EACAC,WAAAA;AAAAA,EACAC,qBAAAA;AAAAA,EACAC,0BAAAA;AAAAA,EACAC,UAAAA;AAAAA,EACAC,MAAAA;AACF,MAAM;AAEEC,QAAAA,IAAsBZ,EAAMa,QAChC,OAAO;AAAA,IACLT,MAAAA;AAAAA,IACAI,qBAAAA;AAAAA,IACAC,0BAAAA;AAAAA,IACAJ,UAAAA;AAAAA,MAEF,CAACD,GAAMI,GAAqBC,GAA0BJ,CAAQ,CAChE,GAEMS,IAAQC,EACZZ,KAAU,IACVG,GACAC,GACAK,CACF;AAEA,SACG,gBAAAZ,EAAA,cAAAD,EAAa,UAAb,EAAsB,OAAO;AAAA,IAAEe,OAAAA;AAAAA,EAAAA,EAC9B,GAAA,gBAAAd,EAAA,cAACgB,GAAkB,EAAA,MAAAL,EAAA,GAAaD,CAAS,CAC3C;AAEJ,GAEaO,IAAiBA,MAAa;AACnCC,QAAAA,IAAUlB,EAAMmB,WAAWpB,CAAY;AAC7C,MAAI,CAACmB;AACG,UAAA,IAAIE,MAAM,oDAAoD;AAEtE,SAAOF,EAAQJ;AACjB;"}
1
+ {"version":3,"file":"KnockProvider.mjs","sources":["../../../../../src/modules/core/context/KnockProvider.tsx"],"sourcesContent":["import Knock, {\n AuthenticateOptions,\n LogLevel,\n UserWithProperties,\n} from \"@knocklabs/client\";\nimport * as React from \"react\";\nimport { PropsWithChildren } from \"react\";\n\nimport { I18nContent, KnockI18nProvider } from \"../../i18n\";\nimport { useAuthenticatedKnockClient } from \"../hooks\";\n\nexport interface KnockProviderState {\n knock: Knock;\n}\n\nconst KnockContext = React.createContext<KnockProviderState | null>(null);\n\nexport type KnockProviderProps = {\n // Knock client props\n apiKey: string | undefined;\n host?: string;\n userToken?: Knock[\"userToken\"];\n onUserTokenExpiring?: AuthenticateOptions[\"onUserTokenExpiring\"];\n timeBeforeExpirationInMs?: AuthenticateOptions[\"timeBeforeExpirationInMs\"];\n // i18n translations\n i18n?: I18nContent;\n logLevel?: LogLevel;\n} & (\n | {\n /**\n * @deprecated The `userId` prop is deprecated and will be removed in a future version.\n * Please pass the `user` prop instead containing an `id` value.\n * example:\n * ```ts\n * <KnockProvider user={{ id: \"user_123\" }}></KnockProvider>\n * ```\n */\n userId: Knock[\"userId\"];\n user?: never;\n }\n | {\n user: UserWithProperties;\n /**\n * @deprecated The `userId` prop is deprecated and will be removed in a future version.\n * Please pass the `user` prop instead containing an `id` value.\n * example:\n * ```ts\n * <KnockProvider user={{ id: \"user_123\" }}></KnockProvider>\n * ```\n */\n userId?: never;\n }\n);\n\nexport const KnockProvider: React.FC<PropsWithChildren<KnockProviderProps>> = ({\n apiKey,\n host,\n logLevel,\n userToken,\n onUserTokenExpiring,\n timeBeforeExpirationInMs,\n children,\n i18n,\n ...props\n}) => {\n const userIdOrUserWithProperties = props?.user || props?.userId;\n\n // We memoize the options here so that we don't create a new object on every re-render\n const authenticateOptions = React.useMemo(\n () => ({\n host,\n onUserTokenExpiring,\n timeBeforeExpirationInMs,\n logLevel,\n }),\n [host, onUserTokenExpiring, timeBeforeExpirationInMs, logLevel],\n );\n\n const knock = useAuthenticatedKnockClient(\n apiKey ?? \"\",\n userIdOrUserWithProperties,\n userToken,\n authenticateOptions,\n );\n\n return (\n <KnockContext.Provider value={{ knock }}>\n <KnockI18nProvider i18n={i18n}>{children}</KnockI18nProvider>\n </KnockContext.Provider>\n );\n};\n\nexport const useKnockClient = (): Knock => {\n const context = React.useContext(KnockContext);\n if (!context) {\n throw new Error(\"useKnockClient must be used within a KnockProvider\");\n }\n return context.knock;\n};\n"],"names":["KnockContext","React","createContext","KnockProvider","apiKey","host","logLevel","userToken","onUserTokenExpiring","timeBeforeExpirationInMs","children","i18n","props","userIdOrUserWithProperties","user","userId","authenticateOptions","useMemo","knock","useAuthenticatedKnockClient","KnockI18nProvider","useKnockClient","context","useContext","Error"],"mappings":";;;;AAeA,MAAMA,IAAeC,EAAMC,cAAyC,IAAI,GAuC3DC,IAAiEA,CAAC;AAAA,EAC7EC,QAAAA;AAAAA,EACAC,MAAAA;AAAAA,EACAC,UAAAA;AAAAA,EACAC,WAAAA;AAAAA,EACAC,qBAAAA;AAAAA,EACAC,0BAAAA;AAAAA,EACAC,UAAAA;AAAAA,EACAC,MAAAA;AAAAA,EACA,GAAGC;AACL,MAAM;AACEC,QAAAA,KAA6BD,KAAAA,gBAAAA,EAAOE,UAAQF,KAAAA,gBAAAA,EAAOG,SAGnDC,IAAsBf,EAAMgB,QAChC,OAAO;AAAA,IACLZ,MAAAA;AAAAA,IACAG,qBAAAA;AAAAA,IACAC,0BAAAA;AAAAA,IACAH,UAAAA;AAAAA,MAEF,CAACD,GAAMG,GAAqBC,GAA0BH,CAAQ,CAChE,GAEMY,IAAQC,EACZf,KAAU,IACVS,GACAN,GACAS,CACF;AAEA,SACG,gBAAAf,EAAA,cAAAD,EAAa,UAAb,EAAsB,OAAO;AAAA,IAAEkB,OAAAA;AAAAA,EAAAA,EAC9B,GAAA,gBAAAjB,EAAA,cAACmB,GAAkB,EAAA,MAAAT,EAAA,GAAaD,CAAS,CAC3C;AAEJ,GAEaW,IAAiBA,MAAa;AACnCC,QAAAA,IAAUrB,EAAMsB,WAAWvB,CAAY;AAC7C,MAAI,CAACsB;AACG,UAAA,IAAIE,MAAM,oDAAoD;AAEtE,SAAOF,EAAQJ;AACjB;"}
@@ -1,27 +1,27 @@
1
- import m from "@knocklabs/client";
2
- import u from "react";
1
+ import l from "@knocklabs/client";
2
+ import a from "react";
3
3
  import "../context/KnockProvider.mjs";
4
- import l from "./useStableOptions.mjs";
4
+ import s from "./useStableOptions.mjs";
5
5
  import "date-fns";
6
- function f(i, n, r, t = {}) {
7
- i.authenticate(n, r, {
6
+ function m(o, c, r, t = {}) {
7
+ o.authenticate(c, r, {
8
8
  onUserTokenExpiring: t == null ? void 0 : t.onUserTokenExpiring,
9
9
  timeBeforeExpirationInMs: t == null ? void 0 : t.timeBeforeExpirationInMs
10
10
  });
11
11
  }
12
- function E(i, n, r, t = {}) {
13
- const a = u.useRef(), c = l(t);
14
- return u.useMemo(() => {
15
- const e = a.current;
16
- if (e && e.isAuthenticated() && (e.userId !== n || e.userToken !== r))
17
- return f(e, n, r, c), e;
18
- e && e.teardown();
19
- const o = new m(i, {
20
- host: c.host,
21
- logLevel: c.logLevel
12
+ function E(o, c, r, t = {}) {
13
+ const f = a.useRef(void 0), i = s(t), e = s(c);
14
+ return a.useMemo(() => {
15
+ const d = typeof e == "string" ? e : e == null ? void 0 : e.id, n = f.current;
16
+ if (n && n.isAuthenticated() && (n.userId !== d || n.userToken !== r))
17
+ return m(n, e, r, i), n;
18
+ n && n.teardown();
19
+ const u = new l(o, {
20
+ host: i.host,
21
+ logLevel: i.logLevel
22
22
  });
23
- return f(o, n, r, c), a.current = o, o;
24
- }, [i, n, r, c]);
23
+ return m(u, e, r, i), f.current = u, u;
24
+ }, [o, e, r, i]);
25
25
  }
26
26
  export {
27
27
  E as default
@@ -1 +1 @@
1
- {"version":3,"file":"useAuthenticatedKnockClient.mjs","sources":["../../../../../src/modules/core/hooks/useAuthenticatedKnockClient.ts"],"sourcesContent":["import Knock, { AuthenticateOptions, KnockOptions } from \"@knocklabs/client\";\nimport React from \"react\";\n\nimport { useStableOptions } from \"../../core\";\n\nfunction authenticateWithOptions(\n knock: Knock,\n userId: Knock[\"userId\"],\n userToken?: Knock[\"userToken\"],\n options: AuthenticateOptions = {},\n) {\n knock.authenticate(userId, userToken, {\n onUserTokenExpiring: options?.onUserTokenExpiring,\n timeBeforeExpirationInMs: options?.timeBeforeExpirationInMs,\n });\n}\n\nexport type AuthenticatedKnockClientOptions = KnockOptions &\n AuthenticateOptions;\n\nfunction useAuthenticatedKnockClient(\n apiKey: string,\n userId: Knock[\"userId\"],\n userToken?: Knock[\"userToken\"],\n options: AuthenticatedKnockClientOptions = {},\n) {\n const knockRef = React.useRef<Knock | undefined>();\n const stableOptions = useStableOptions(options);\n\n return React.useMemo(() => {\n const currentKnock = knockRef.current;\n\n // If the userId and the userToken changes then just reauth\n if (\n currentKnock &&\n currentKnock.isAuthenticated() &&\n (currentKnock.userId !== userId || currentKnock.userToken !== userToken)\n ) {\n authenticateWithOptions(currentKnock, userId, userToken, stableOptions);\n return currentKnock;\n }\n\n if (currentKnock) {\n currentKnock.teardown();\n }\n\n // Otherwise instantiate a new Knock client\n const knock = new Knock(apiKey, {\n host: stableOptions.host,\n logLevel: stableOptions.logLevel,\n });\n\n authenticateWithOptions(knock, userId, userToken, stableOptions);\n knockRef.current = knock;\n\n return knock;\n }, [apiKey, userId, userToken, stableOptions]);\n}\n\nexport default useAuthenticatedKnockClient;\n"],"names":["authenticateWithOptions","knock","userId","userToken","options","authenticate","onUserTokenExpiring","timeBeforeExpirationInMs","useAuthenticatedKnockClient","apiKey","knockRef","React","useRef","stableOptions","useStableOptions","useMemo","currentKnock","current","isAuthenticated","teardown","Knock","host","logLevel"],"mappings":";;;;;AAKA,SAASA,EACPC,GACAC,GACAC,GACAC,IAA+B,CAAA,GAC/B;AACMC,EAAAA,EAAAA,aAAaH,GAAQC,GAAW;AAAA,IACpCG,qBAAqBF,KAAAA,gBAAAA,EAASE;AAAAA,IAC9BC,0BAA0BH,KAAAA,gBAAAA,EAASG;AAAAA,EAAAA,CACpC;AACH;AAKA,SAASC,EACPC,GACAP,GACAC,GACAC,IAA2C,CAAA,GAC3C;AACMM,QAAAA,IAAWC,EAAMC,OAA0B,GAC3CC,IAAgBC,EAAiBV,CAAO;AAEvCO,SAAAA,EAAMI,QAAQ,MAAM;AACzB,UAAMC,IAAeN,EAASO;AAI5BD,QAAAA,KACAA,EAAaE,gBAAgB,MAC5BF,EAAad,WAAWA,KAAUc,EAAab,cAAcA;AAEtCa,aAAAA,EAAAA,GAAcd,GAAQC,GAAWU,CAAa,GAC/DG;AAGT,IAAIA,KACFA,EAAaG,SAAS;AAIlBlB,UAAAA,IAAQ,IAAImB,EAAMX,GAAQ;AAAA,MAC9BY,MAAMR,EAAcQ;AAAAA,MACpBC,UAAUT,EAAcS;AAAAA,IAAAA,CACzB;AAEuBrB,WAAAA,EAAAA,GAAOC,GAAQC,GAAWU,CAAa,GAC/DH,EAASO,UAAUhB,GAEZA;AAAAA,KACN,CAACQ,GAAQP,GAAQC,GAAWU,CAAa,CAAC;AAC/C;"}
1
+ {"version":3,"file":"useAuthenticatedKnockClient.mjs","sources":["../../../../../src/modules/core/hooks/useAuthenticatedKnockClient.ts"],"sourcesContent":["import Knock, {\n AuthenticateOptions,\n KnockOptions,\n UserId,\n UserIdOrUserWithProperties,\n} from \"@knocklabs/client\";\nimport React from \"react\";\n\nimport { useStableOptions } from \"../../core\";\n\nfunction authenticateWithOptions(\n knock: Knock,\n userIdOrUserWithProperties: UserIdOrUserWithProperties,\n userToken?: Knock[\"userToken\"],\n options: AuthenticateOptions = {},\n) {\n knock.authenticate(userIdOrUserWithProperties, userToken, {\n onUserTokenExpiring: options?.onUserTokenExpiring,\n timeBeforeExpirationInMs: options?.timeBeforeExpirationInMs,\n });\n}\n\nexport type AuthenticatedKnockClientOptions = KnockOptions &\n AuthenticateOptions;\n\n/**\n * @deprecated Passing `userId` as a `string` is deprecated and will be removed in a future version.\n * Please pass a `user` object instead containing an `id` value.\n * example:\n * ```ts\n * useAuthenticatedKnockClient(\"pk_test_12345\", { id: \"user_123\" });\n * ```\n */\nfunction useAuthenticatedKnockClient(\n apiKey: string,\n userIdOrUserWithProperties: UserId,\n userToken?: Knock[\"userToken\"],\n options?: AuthenticatedKnockClientOptions,\n): Knock;\nfunction useAuthenticatedKnockClient(\n apiKey: string,\n userIdOrUserWithProperties: UserIdOrUserWithProperties,\n userToken?: Knock[\"userToken\"],\n options?: AuthenticatedKnockClientOptions,\n): Knock;\nfunction useAuthenticatedKnockClient(\n apiKey: string,\n userIdOrUserWithProperties: UserIdOrUserWithProperties,\n userToken?: Knock[\"userToken\"],\n options: AuthenticatedKnockClientOptions = {},\n) {\n const knockRef = React.useRef<Knock | undefined>(undefined);\n\n const stableOptions = useStableOptions(options);\n const stableUserIdOrObject = useStableOptions(userIdOrUserWithProperties);\n\n return React.useMemo(() => {\n const userId =\n typeof stableUserIdOrObject === \"string\"\n ? stableUserIdOrObject\n : stableUserIdOrObject?.id;\n\n const currentKnock = knockRef.current;\n\n // If the userId and the userToken changes then just reauth\n if (\n currentKnock &&\n currentKnock.isAuthenticated() &&\n (currentKnock.userId !== userId || currentKnock.userToken !== userToken)\n ) {\n authenticateWithOptions(\n currentKnock,\n stableUserIdOrObject,\n userToken,\n stableOptions,\n );\n return currentKnock;\n }\n\n if (currentKnock) {\n currentKnock.teardown();\n }\n\n // Otherwise instantiate a new Knock client\n const knock = new Knock(apiKey, {\n host: stableOptions.host,\n logLevel: stableOptions.logLevel,\n });\n\n authenticateWithOptions(\n knock,\n stableUserIdOrObject,\n userToken,\n stableOptions,\n );\n knockRef.current = knock;\n\n return knock;\n }, [apiKey, stableUserIdOrObject, userToken, stableOptions]);\n}\n\nexport default useAuthenticatedKnockClient;\n"],"names":["authenticateWithOptions","knock","userIdOrUserWithProperties","userToken","options","authenticate","onUserTokenExpiring","timeBeforeExpirationInMs","useAuthenticatedKnockClient","apiKey","knockRef","React","useRef","undefined","stableOptions","useStableOptions","stableUserIdOrObject","useMemo","userId","id","currentKnock","current","isAuthenticated","teardown","Knock","host","logLevel"],"mappings":";;;;;AAUA,SAASA,EACPC,GACAC,GACAC,GACAC,IAA+B,CAAA,GAC/B;AACMC,EAAAA,EAAAA,aAAaH,GAA4BC,GAAW;AAAA,IACxDG,qBAAqBF,KAAAA,gBAAAA,EAASE;AAAAA,IAC9BC,0BAA0BH,KAAAA,gBAAAA,EAASG;AAAAA,EAAAA,CACpC;AACH;AAyBA,SAASC,EACPC,GACAP,GACAC,GACAC,IAA2C,CAAA,GAC3C;AACMM,QAAAA,IAAWC,EAAMC,OAA0BC,MAAS,GAEpDC,IAAgBC,EAAiBX,CAAO,GACxCY,IAAuBD,EAAiBb,CAA0B;AAEjES,SAAAA,EAAMM,QAAQ,MAAM;AACzB,UAAMC,IACJ,OAAOF,KAAyB,WAC5BA,IACAA,KAAAA,gBAAAA,EAAsBG,IAEtBC,IAAeV,EAASW;AAI5BD,QAAAA,KACAA,EAAaE,gBAAgB,MAC5BF,EAAaF,WAAWA,KAAUE,EAAajB,cAAcA;AAG5DiB,aAAAA,EAAAA,GACAJ,GACAb,GACAW,CACF,GACOM;AAGT,IAAIA,KACFA,EAAaG,SAAS;AAIlBtB,UAAAA,IAAQ,IAAIuB,EAAMf,GAAQ;AAAA,MAC9BgB,MAAMX,EAAcW;AAAAA,MACpBC,UAAUZ,EAAcY;AAAAA,IAAAA,CACzB;AAGCzB,WAAAA,EAAAA,GACAe,GACAb,GACAW,CACF,GACAJ,EAASW,UAAUpB,GAEZA;AAAAA,KACN,CAACQ,GAAQO,GAAsBb,GAAWW,CAAa,CAAC;AAC7D;"}
@@ -1,7 +1,7 @@
1
1
  import u from "fast-deep-equal";
2
2
  import { useRef as n, useMemo as f } from "react";
3
3
  function c(e) {
4
- const t = n();
4
+ const t = n(void 0);
5
5
  return f(() => {
6
6
  const r = t.current;
7
7
  return r && u(e, r) ? r : (t.current = e, e);
@@ -1 +1 @@
1
- {"version":3,"file":"useStableOptions.mjs","sources":["../../../../../src/modules/core/hooks/useStableOptions.ts"],"sourcesContent":["import fastDeepEqual from \"fast-deep-equal\";\nimport { useMemo, useRef } from \"react\";\n\nexport default function useStableOptions<T>(options: T): T {\n const optionsRef = useRef<T>();\n\n return useMemo(() => {\n const currentOptions = optionsRef.current;\n\n if (currentOptions && fastDeepEqual(options, currentOptions)) {\n return currentOptions;\n }\n\n optionsRef.current = options;\n return options;\n }, [options]);\n}\n"],"names":["useStableOptions","options","optionsRef","useRef","useMemo","currentOptions","current","fastDeepEqual"],"mappings":";;AAGA,SAAwBA,EAAoBC,GAAe;AACzD,QAAMC,IAAaC,EAAU;AAE7B,SAAOC,EAAQ,MAAM;AACnB,UAAMC,IAAiBH,EAAWI;AAElC,WAAID,KAAkBE,EAAcN,GAASI,CAAc,IAClDA,KAGTH,EAAWI,UAAUL,GACdA;AAAAA,EAAAA,GACN,CAACA,CAAO,CAAC;AACd;"}
1
+ {"version":3,"file":"useStableOptions.mjs","sources":["../../../../../src/modules/core/hooks/useStableOptions.ts"],"sourcesContent":["import fastDeepEqual from \"fast-deep-equal\";\nimport { useMemo, useRef } from \"react\";\n\nexport default function useStableOptions<T>(options: T): T {\n const optionsRef = useRef<T>(undefined);\n\n return useMemo(() => {\n const currentOptions = optionsRef.current;\n\n if (currentOptions && fastDeepEqual(options, currentOptions)) {\n return currentOptions;\n }\n\n optionsRef.current = options;\n return options;\n }, [options]);\n}\n"],"names":["useStableOptions","options","optionsRef","useRef","undefined","useMemo","currentOptions","current","fastDeepEqual"],"mappings":";;AAGA,SAAwBA,EAAoBC,GAAe;AACnDC,QAAAA,IAAaC,EAAUC,MAAS;AAEtC,SAAOC,EAAQ,MAAM;AACnB,UAAMC,IAAiBJ,EAAWK;AAElC,WAAID,KAAkBE,EAAcP,GAASK,CAAc,IAClDA,KAGTJ,EAAWK,UAAUN,GACdA;AAAAA,EAAAA,GACN,CAACA,CAAO,CAAC;AACd;"}
@@ -1,20 +1,41 @@
1
- import { default as Knock, AuthenticateOptions, LogLevel } from '@knocklabs/client';
1
+ import { default as Knock, AuthenticateOptions, LogLevel, UserWithProperties } from '@knocklabs/client';
2
2
  import { PropsWithChildren } from 'react';
3
3
  import { I18nContent } from '../../i18n';
4
4
  import * as React from "react";
5
5
  export interface KnockProviderState {
6
6
  knock: Knock;
7
7
  }
8
- export interface KnockProviderProps {
8
+ export type KnockProviderProps = {
9
9
  apiKey: string | undefined;
10
10
  host?: string;
11
- userId: Knock["userId"];
12
11
  userToken?: Knock["userToken"];
13
12
  onUserTokenExpiring?: AuthenticateOptions["onUserTokenExpiring"];
14
13
  timeBeforeExpirationInMs?: AuthenticateOptions["timeBeforeExpirationInMs"];
15
14
  i18n?: I18nContent;
16
15
  logLevel?: LogLevel;
17
- }
16
+ } & ({
17
+ /**
18
+ * @deprecated The `userId` prop is deprecated and will be removed in a future version.
19
+ * Please pass the `user` prop instead containing an `id` value.
20
+ * example:
21
+ * ```ts
22
+ * <KnockProvider user={{ id: "user_123" }}></KnockProvider>
23
+ * ```
24
+ */
25
+ userId: Knock["userId"];
26
+ user?: never;
27
+ } | {
28
+ user: UserWithProperties;
29
+ /**
30
+ * @deprecated The `userId` prop is deprecated and will be removed in a future version.
31
+ * Please pass the `user` prop instead containing an `id` value.
32
+ * example:
33
+ * ```ts
34
+ * <KnockProvider user={{ id: "user_123" }}></KnockProvider>
35
+ * ```
36
+ */
37
+ userId?: never;
38
+ });
18
39
  export declare const KnockProvider: React.FC<PropsWithChildren<KnockProviderProps>>;
19
40
  export declare const useKnockClient: () => Knock;
20
41
  //# sourceMappingURL=KnockProvider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"KnockProvider.d.ts","sourceRoot":"","sources":["../../../../../src/modules/core/context/KnockProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAqB,MAAM,YAAY,CAAC;AAG5D,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,KAAK,CAAC;CACd;AAID,MAAM,WAAW,kBAAkB;IAEjC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,MAAM,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;IACxB,SAAS,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;IAC/B,mBAAmB,CAAC,EAAE,mBAAmB,CAAC,qBAAqB,CAAC,CAAC;IACjE,wBAAwB,CAAC,EAAE,mBAAmB,CAAC,0BAA0B,CAAC,CAAC;IAE3E,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,CAkCzE,CAAC;AAEF,eAAO,MAAM,cAAc,QAAO,KAMjC,CAAC"}
1
+ {"version":3,"file":"KnockProvider.d.ts","sourceRoot":"","sources":["../../../../../src/modules/core/context/KnockProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EACZ,mBAAmB,EACnB,QAAQ,EACR,kBAAkB,EACnB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAqB,MAAM,YAAY,CAAC;AAG5D,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,KAAK,CAAC;CACd;AAID,MAAM,MAAM,kBAAkB,GAAG;IAE/B,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC;IAC/B,mBAAmB,CAAC,EAAE,mBAAmB,CAAC,qBAAqB,CAAC,CAAC;IACjE,wBAAwB,CAAC,EAAE,mBAAmB,CAAC,0BAA0B,CAAC,CAAC;IAE3E,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB,GAAG,CACA;IACE;;;;;;;OAOG;IACH,MAAM,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;IACxB,IAAI,CAAC,EAAE,KAAK,CAAC;CACd,GACD;IACE,IAAI,EAAE,kBAAkB,CAAC;IACzB;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,KAAK,CAAC;CAChB,CACJ,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,CAoCzE,CAAC;AAEF,eAAO,MAAM,cAAc,QAAO,KAMjC,CAAC"}
@@ -1,5 +1,14 @@
1
- import { default as Knock, AuthenticateOptions, KnockOptions } from '@knocklabs/client';
1
+ import { default as Knock, AuthenticateOptions, KnockOptions, UserId, UserIdOrUserWithProperties } from '@knocklabs/client';
2
2
  export type AuthenticatedKnockClientOptions = KnockOptions & AuthenticateOptions;
3
- declare function useAuthenticatedKnockClient(apiKey: string, userId: Knock["userId"], userToken?: Knock["userToken"], options?: AuthenticatedKnockClientOptions): Knock;
3
+ /**
4
+ * @deprecated Passing `userId` as a `string` is deprecated and will be removed in a future version.
5
+ * Please pass a `user` object instead containing an `id` value.
6
+ * example:
7
+ * ```ts
8
+ * useAuthenticatedKnockClient("pk_test_12345", { id: "user_123" });
9
+ * ```
10
+ */
11
+ declare function useAuthenticatedKnockClient(apiKey: string, userIdOrUserWithProperties: UserId, userToken?: Knock["userToken"], options?: AuthenticatedKnockClientOptions): Knock;
12
+ declare function useAuthenticatedKnockClient(apiKey: string, userIdOrUserWithProperties: UserIdOrUserWithProperties, userToken?: Knock["userToken"], options?: AuthenticatedKnockClientOptions): Knock;
4
13
  export default useAuthenticatedKnockClient;
5
14
  //# sourceMappingURL=useAuthenticatedKnockClient.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useAuthenticatedKnockClient.d.ts","sourceRoot":"","sources":["../../../../../src/modules/core/hooks/useAuthenticatedKnockClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAiB7E,MAAM,MAAM,+BAA+B,GAAG,YAAY,GACxD,mBAAmB,CAAC;AAEtB,iBAAS,2BAA2B,CAClC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,KAAK,CAAC,QAAQ,CAAC,EACvB,SAAS,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,EAC9B,OAAO,GAAE,+BAAoC,SAiC9C;AAED,eAAe,2BAA2B,CAAC"}
1
+ {"version":3,"file":"useAuthenticatedKnockClient.d.ts","sourceRoot":"","sources":["../../../../../src/modules/core/hooks/useAuthenticatedKnockClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EACZ,mBAAmB,EACnB,YAAY,EACZ,MAAM,EACN,0BAA0B,EAC3B,MAAM,mBAAmB,CAAC;AAiB3B,MAAM,MAAM,+BAA+B,GAAG,YAAY,GACxD,mBAAmB,CAAC;AAEtB;;;;;;;GAOG;AACH,iBAAS,2BAA2B,CAClC,MAAM,EAAE,MAAM,EACd,0BAA0B,EAAE,MAAM,EAClC,SAAS,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,EAC9B,OAAO,CAAC,EAAE,+BAA+B,GACxC,KAAK,CAAC;AACT,iBAAS,2BAA2B,CAClC,MAAM,EAAE,MAAM,EACd,0BAA0B,EAAE,0BAA0B,EACtD,SAAS,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,EAC9B,OAAO,CAAC,EAAE,+BAA+B,GACxC,KAAK,CAAC;AAyDT,eAAe,2BAA2B,CAAC"}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@knocklabs/react-core",
3
3
  "description": "A set of React components to build notification experiences powered by Knock",
4
4
  "author": "@knocklabs",
5
- "version": "0.6.15",
5
+ "version": "0.7.1",
6
6
  "license": "MIT",
7
7
  "main": "dist/cjs/index.js",
8
8
  "module": "dist/esm/index.mjs",
@@ -47,16 +47,18 @@
47
47
  "react": "^16.11.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
48
48
  },
49
49
  "dependencies": {
50
- "@knocklabs/client": "^0.14.11",
50
+ "@knocklabs/client": "^0.15.0",
51
51
  "@tanstack/react-store": "^0.7.1",
52
52
  "date-fns": "^4.0.0",
53
53
  "fast-deep-equal": "^3.1.3",
54
54
  "swr": "^2.3.3"
55
55
  },
56
56
  "devDependencies": {
57
+ "@codecov/vite-plugin": "^1.9.1",
57
58
  "@testing-library/dom": "^10.4.0",
58
59
  "@testing-library/react": "^16.3.0",
59
- "@types/react": "^18.3.6",
60
+ "@types/react": "^19.1.8",
61
+ "@types/react-dom": "^19.1.6",
60
62
  "@typescript-eslint/eslint-plugin": "^8.32.0",
61
63
  "@typescript-eslint/parser": "^8.32.1",
62
64
  "@vitejs/plugin-react": "^4.5.1",
@@ -65,8 +67,8 @@
65
67
  "eslint-plugin-react-hooks": "^5.2.0",
66
68
  "eslint-plugin-react-refresh": "^0.4.14",
67
69
  "jsdom": "^26.1.0",
68
- "react": "^18.2.0",
69
- "react-dom": "^18.2.0",
70
+ "react": "^19.0.0",
71
+ "react-dom": "^19.0.0",
70
72
  "rimraf": "^6.0.1",
71
73
  "rollup-plugin-execute": "^1.1.1",
72
74
  "typescript": "^5.8.3",
@@ -1,4 +1,8 @@
1
- import Knock, { AuthenticateOptions, LogLevel } from "@knocklabs/client";
1
+ import Knock, {
2
+ AuthenticateOptions,
3
+ LogLevel,
4
+ UserWithProperties,
5
+ } from "@knocklabs/client";
2
6
  import * as React from "react";
3
7
  import { PropsWithChildren } from "react";
4
8
 
@@ -11,31 +15,56 @@ export interface KnockProviderState {
11
15
 
12
16
  const KnockContext = React.createContext<KnockProviderState | null>(null);
13
17
 
14
- export interface KnockProviderProps {
18
+ export type KnockProviderProps = {
15
19
  // Knock client props
16
20
  apiKey: string | undefined;
17
21
  host?: string;
18
- // Authentication props
19
- userId: Knock["userId"];
20
22
  userToken?: Knock["userToken"];
21
23
  onUserTokenExpiring?: AuthenticateOptions["onUserTokenExpiring"];
22
24
  timeBeforeExpirationInMs?: AuthenticateOptions["timeBeforeExpirationInMs"];
23
25
  // i18n translations
24
26
  i18n?: I18nContent;
25
27
  logLevel?: LogLevel;
26
- }
28
+ } & (
29
+ | {
30
+ /**
31
+ * @deprecated The `userId` prop is deprecated and will be removed in a future version.
32
+ * Please pass the `user` prop instead containing an `id` value.
33
+ * example:
34
+ * ```ts
35
+ * <KnockProvider user={{ id: "user_123" }}></KnockProvider>
36
+ * ```
37
+ */
38
+ userId: Knock["userId"];
39
+ user?: never;
40
+ }
41
+ | {
42
+ user: UserWithProperties;
43
+ /**
44
+ * @deprecated The `userId` prop is deprecated and will be removed in a future version.
45
+ * Please pass the `user` prop instead containing an `id` value.
46
+ * example:
47
+ * ```ts
48
+ * <KnockProvider user={{ id: "user_123" }}></KnockProvider>
49
+ * ```
50
+ */
51
+ userId?: never;
52
+ }
53
+ );
27
54
 
28
55
  export const KnockProvider: React.FC<PropsWithChildren<KnockProviderProps>> = ({
29
56
  apiKey,
30
57
  host,
31
58
  logLevel,
32
- userId,
33
59
  userToken,
34
60
  onUserTokenExpiring,
35
61
  timeBeforeExpirationInMs,
36
62
  children,
37
63
  i18n,
64
+ ...props
38
65
  }) => {
66
+ const userIdOrUserWithProperties = props?.user || props?.userId;
67
+
39
68
  // We memoize the options here so that we don't create a new object on every re-render
40
69
  const authenticateOptions = React.useMemo(
41
70
  () => ({
@@ -49,7 +78,7 @@ export const KnockProvider: React.FC<PropsWithChildren<KnockProviderProps>> = ({
49
78
 
50
79
  const knock = useAuthenticatedKnockClient(
51
80
  apiKey ?? "",
52
- userId,
81
+ userIdOrUserWithProperties,
53
82
  userToken,
54
83
  authenticateOptions,
55
84
  );
@@ -1,15 +1,20 @@
1
- import Knock, { AuthenticateOptions, KnockOptions } from "@knocklabs/client";
1
+ import Knock, {
2
+ AuthenticateOptions,
3
+ KnockOptions,
4
+ UserId,
5
+ UserIdOrUserWithProperties,
6
+ } from "@knocklabs/client";
2
7
  import React from "react";
3
8
 
4
9
  import { useStableOptions } from "../../core";
5
10
 
6
11
  function authenticateWithOptions(
7
12
  knock: Knock,
8
- userId: Knock["userId"],
13
+ userIdOrUserWithProperties: UserIdOrUserWithProperties,
9
14
  userToken?: Knock["userToken"],
10
15
  options: AuthenticateOptions = {},
11
16
  ) {
12
- knock.authenticate(userId, userToken, {
17
+ knock.authenticate(userIdOrUserWithProperties, userToken, {
13
18
  onUserTokenExpiring: options?.onUserTokenExpiring,
14
19
  timeBeforeExpirationInMs: options?.timeBeforeExpirationInMs,
15
20
  });
@@ -18,16 +23,43 @@ function authenticateWithOptions(
18
23
  export type AuthenticatedKnockClientOptions = KnockOptions &
19
24
  AuthenticateOptions;
20
25
 
26
+ /**
27
+ * @deprecated Passing `userId` as a `string` is deprecated and will be removed in a future version.
28
+ * Please pass a `user` object instead containing an `id` value.
29
+ * example:
30
+ * ```ts
31
+ * useAuthenticatedKnockClient("pk_test_12345", { id: "user_123" });
32
+ * ```
33
+ */
21
34
  function useAuthenticatedKnockClient(
22
35
  apiKey: string,
23
- userId: Knock["userId"],
36
+ userIdOrUserWithProperties: UserId,
37
+ userToken?: Knock["userToken"],
38
+ options?: AuthenticatedKnockClientOptions,
39
+ ): Knock;
40
+ function useAuthenticatedKnockClient(
41
+ apiKey: string,
42
+ userIdOrUserWithProperties: UserIdOrUserWithProperties,
43
+ userToken?: Knock["userToken"],
44
+ options?: AuthenticatedKnockClientOptions,
45
+ ): Knock;
46
+ function useAuthenticatedKnockClient(
47
+ apiKey: string,
48
+ userIdOrUserWithProperties: UserIdOrUserWithProperties,
24
49
  userToken?: Knock["userToken"],
25
50
  options: AuthenticatedKnockClientOptions = {},
26
51
  ) {
27
- const knockRef = React.useRef<Knock | undefined>();
52
+ const knockRef = React.useRef<Knock | undefined>(undefined);
53
+
28
54
  const stableOptions = useStableOptions(options);
55
+ const stableUserIdOrObject = useStableOptions(userIdOrUserWithProperties);
29
56
 
30
57
  return React.useMemo(() => {
58
+ const userId =
59
+ typeof stableUserIdOrObject === "string"
60
+ ? stableUserIdOrObject
61
+ : stableUserIdOrObject?.id;
62
+
31
63
  const currentKnock = knockRef.current;
32
64
 
33
65
  // If the userId and the userToken changes then just reauth
@@ -36,7 +68,12 @@ function useAuthenticatedKnockClient(
36
68
  currentKnock.isAuthenticated() &&
37
69
  (currentKnock.userId !== userId || currentKnock.userToken !== userToken)
38
70
  ) {
39
- authenticateWithOptions(currentKnock, userId, userToken, stableOptions);
71
+ authenticateWithOptions(
72
+ currentKnock,
73
+ stableUserIdOrObject,
74
+ userToken,
75
+ stableOptions,
76
+ );
40
77
  return currentKnock;
41
78
  }
42
79
 
@@ -50,11 +87,16 @@ function useAuthenticatedKnockClient(
50
87
  logLevel: stableOptions.logLevel,
51
88
  });
52
89
 
53
- authenticateWithOptions(knock, userId, userToken, stableOptions);
90
+ authenticateWithOptions(
91
+ knock,
92
+ stableUserIdOrObject,
93
+ userToken,
94
+ stableOptions,
95
+ );
54
96
  knockRef.current = knock;
55
97
 
56
98
  return knock;
57
- }, [apiKey, userId, userToken, stableOptions]);
99
+ }, [apiKey, stableUserIdOrObject, userToken, stableOptions]);
58
100
  }
59
101
 
60
102
  export default useAuthenticatedKnockClient;
@@ -2,7 +2,7 @@ import fastDeepEqual from "fast-deep-equal";
2
2
  import { useMemo, useRef } from "react";
3
3
 
4
4
  export default function useStableOptions<T>(options: T): T {
5
- const optionsRef = useRef<T>();
5
+ const optionsRef = useRef<T>(undefined);
6
6
 
7
7
  return useMemo(() => {
8
8
  const currentOptions = optionsRef.current;