@dynamic-labs-sdk/react-hooks 0.25.2 → 0.26.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.
|
@@ -5,7 +5,7 @@ let react_jsx_runtime = require("react/jsx-runtime");
|
|
|
5
5
|
|
|
6
6
|
//#region package.json
|
|
7
7
|
var name = "@dynamic-labs-sdk/react-hooks";
|
|
8
|
-
var version = "0.
|
|
8
|
+
var version = "0.26.1";
|
|
9
9
|
|
|
10
10
|
//#endregion
|
|
11
11
|
//#region src/modules/DynamicContext/DynamicContext.ts
|
|
@@ -161,4 +161,4 @@ exports.useSocialAccounts = useSocialAccounts;
|
|
|
161
161
|
exports.useUser = useUser;
|
|
162
162
|
exports.useWalletAccounts = useWalletAccounts;
|
|
163
163
|
exports.useWalletProviders = useWalletProviders;
|
|
164
|
-
//# sourceMappingURL=index.cjs.
|
|
164
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["BaseError","packageName","packageVersion"],"sources":["../package.json","../src/modules/DynamicContext/DynamicContext.ts","../src/modules/DynamicContext/DynamicProvider.tsx","../src/errors/MissingProviderError/MissingProviderError.ts","../src/modules/DynamicContext/useDynamicClient.ts","../src/hooks/useEvent/useEvent.ts","../src/foundation/useClientState/useClientState.ts","../src/hooks/useInitStatus/useInitStatus.ts","../src/hooks/useSessionExpiresAt/useSessionExpiresAt.ts","../src/hooks/useSocialAccounts/useSocialAccounts.ts","../src/hooks/useUser/useUser.ts","../src/hooks/useWalletAccounts/useWalletAccounts.ts","../src/hooks/useWalletProviders/useWalletProviders.ts","../src/exports/index.ts"],"sourcesContent":["","import type { DynamicClient } from '@dynamic-labs-sdk/client';\nimport { createContext } from 'react';\n\n/**\n * Internal React context for providing the DynamicClient instance to hooks.\n */\nexport const DynamicContext = createContext<DynamicClient | null>(null);\n","import type { DynamicClient } from '@dynamic-labs-sdk/client';\nimport type { PropsWithChildren } from 'react';\n\nimport { DynamicContext } from './DynamicContext';\n\ntype DynamicProviderProps = PropsWithChildren<{\n client: DynamicClient;\n}>;\n\n/**\n * Provides the DynamicClient instance to all child hooks.\n *\n * Wrap your application with this provider and pass your client instance\n * so that hooks like useUser, useWalletAccounts, etc. can access it.\n */\nexport const DynamicProvider = ({ children, client }: DynamicProviderProps) => (\n <DynamicContext.Provider value={client}>{children}</DynamicContext.Provider>\n);\n","import { BaseError } from '@dynamic-labs-sdk/client';\n\nexport class MissingProviderError extends BaseError {\n constructor() {\n super({\n cause: null,\n code: 'MISSING_PROVIDER',\n docsUrl: null,\n name: 'MissingProviderError',\n shortMessage:\n 'Hook must be used within a <DynamicProvider>.\\nWrap your component tree with <DynamicProvider client={client}>.',\n });\n }\n}\n","import type { DynamicClient } from '@dynamic-labs-sdk/client';\nimport { useContext } from 'react';\n\nimport { MissingProviderError } from '../../errors/MissingProviderError/MissingProviderError';\nimport { DynamicContext } from './DynamicContext';\n\n/**\n * Internal hook to access the DynamicClient from context.\n * Throws if used outside of DynamicProvider.\n */\nexport const useDynamicClient = (): DynamicClient => {\n const client = useContext(DynamicContext);\n\n if (!client) {\n throw new MissingProviderError();\n }\n\n return client;\n};\n","import { type OnEventParams, onEvent } from '@dynamic-labs-sdk/client';\nimport { useEffect, useRef } from 'react';\n\nimport { useDynamicClient } from '../../modules/DynamicContext';\n\n/**\n * Subscribes to a Dynamic client event.\n *\n * Uses a ref to always call the latest listener without re-subscribing,\n * and cleans up the subscription on unmount or event name change.\n */\nexport const useEvent = <E extends keyof DynamicEvents>({\n event,\n listener,\n}: OnEventParams<E>) => {\n const client = useDynamicClient();\n const callbackRef = useRef(listener);\n\n callbackRef.current = listener;\n\n useEffect(\n () =>\n onEvent(\n {\n event,\n listener: (...args: any[]) => {\n // @ts-expect-error - Ignore the type error because we are using the ref\n callbackRef.current(...args);\n },\n },\n client\n ),\n [event, client]\n );\n};\n","import type { DynamicClient } from '@dynamic-labs-sdk/client';\nimport { onEvent } from '@dynamic-labs-sdk/client';\nimport { useRef, useSyncExternalStore } from 'react';\n\nimport { useDynamicClient } from '../../modules/DynamicContext';\n\n/**\n * Internal hook that bridges Dynamic client event-driven state to React.\n *\n * Subscribes to a client event and re-derives a snapshot via the selector\n * each time the event fires, using useSyncExternalStore for tear-free reads.\n */\n// eslint-disable-next-line custom-rules/require-single-object-param\nexport const useClientState = <T>(\n eventName: keyof DynamicEvents,\n getSnapshot: (client: DynamicClient) => T\n): T => {\n const client = useDynamicClient();\n const valueRef = useRef(getSnapshot(client));\n\n return useSyncExternalStore(\n (onStoreChange: VoidFunction) =>\n onEvent(\n {\n event: eventName,\n listener: () => {\n valueRef.current = getSnapshot(client);\n\n onStoreChange();\n },\n },\n client\n ),\n () => valueRef.current,\n () => valueRef.current\n );\n};\n","import { useClientState } from '../../foundation/useClientState/useClientState';\n\n/**\n * Returns the current initialization status of the Dynamic client.\n *\n * Possible values: 'uninitialized', 'in-progress', 'finished', 'failed'.\n */\nexport const useInitStatus = () =>\n useClientState('initStatusChanged', (client) => client.initStatus);\n","import { useClientState } from '../../foundation/useClientState/useClientState';\n\n/**\n * Returns the session expiration date, or null if no active session.\n *\n * Re-renders when the user changes (which includes session updates).\n */\nexport const useSessionExpiresAt = () =>\n useClientState('userChanged', (client) => client.sessionExpiresAt);\n","import { getUserSocialAccounts } from '@dynamic-labs-sdk/client';\n\nimport { useClientState } from '../../foundation/useClientState/useClientState';\n\n/**\n * Returns the current user's linked social accounts.\n *\n * Re-renders when the user changes.\n */\nexport const useSocialAccounts = () =>\n useClientState('userChanged', (client) => getUserSocialAccounts(client));\n","import { useClientState } from '../../foundation/useClientState/useClientState';\n\n/**\n * Returns the current authenticated user, or null if not authenticated.\n *\n * Re-renders when the user changes (login, logout, profile update).\n */\nexport const useUser = () =>\n useClientState('userChanged', (client) => client.user);\n","import type { WalletAccount } from '@dynamic-labs-sdk/client';\nimport { getWalletAccounts } from '@dynamic-labs-sdk/client';\n\nimport { useClientState } from '../../foundation/useClientState/useClientState';\n\n/**\n * Returns all wallet accounts connected to the current user.\n *\n * Re-renders when wallet accounts change (connect, disconnect, verify).\n */\nexport const useWalletAccounts = (): WalletAccount[] =>\n useClientState('walletAccountsChanged', (client) =>\n getWalletAccounts(client)\n );\n","import { getAvailableWalletProvidersData } from '@dynamic-labs-sdk/client';\n\nimport { useClientState } from '../../foundation/useClientState/useClientState';\n\n/**\n * Returns the available wallet providers and their data.\n *\n * Re-renders when a wallet provider changes (e.g. network switch).\n */\nexport const useWalletProviders = () =>\n useClientState('walletProviderChanged', (client) =>\n getAvailableWalletProvidersData(client)\n );\n","import { assertPackageVersion } from '@dynamic-labs-sdk/assert-package-version';\n\nimport {\n name as packageName,\n version as packageVersion,\n} from '../../package.json';\nassertPackageVersion(packageName, packageVersion);\n\nexport { useEvent } from '../hooks/useEvent/useEvent';\nexport { useInitStatus } from '../hooks/useInitStatus/useInitStatus';\nexport { useSessionExpiresAt } from '../hooks/useSessionExpiresAt/useSessionExpiresAt';\nexport { useSocialAccounts } from '../hooks/useSocialAccounts/useSocialAccounts';\nexport { useUser } from '../hooks/useUser/useUser';\nexport { useWalletAccounts } from '../hooks/useWalletAccounts/useWalletAccounts';\nexport { useWalletProviders } from '../hooks/useWalletProviders/useWalletProviders';\nexport { DynamicProvider, useDynamicClient } from '../modules/DynamicContext';\n"],"mappings":";;;;;;;;;;;;;;ACMA,MAAa,0CAAqD,KAAK;;;;;;;;;;ACSvE,MAAa,mBAAmB,EAAE,UAAU,aAC1C,2CAAC,eAAe;CAAS,OAAO;CAAS;EAAmC;;;;ACd9E,IAAa,uBAAb,cAA0CA,mCAAU;CAClD,cAAc;AACZ,QAAM;GACJ,OAAO;GACP,MAAM;GACN,SAAS;GACT,MAAM;GACN,cACE;GACH,CAAC;;;;;;;;;;ACDN,MAAa,yBAAwC;CACnD,MAAM,+BAAoB,eAAe;AAEzC,KAAI,CAAC,OACH,OAAM,IAAI,sBAAsB;AAGlC,QAAO;;;;;;;;;;;AC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