React Hooks Reference
Complete reference for all React hooks -- signatures, return types, state management, and error handling
React Hooks Reference
All hooks must be used within a NeroMpcAuthProvider. If used outside this provider, hooks throw: useNeroMpcAuthContext must be used within a NeroMpcAuthProvider.
All hooks follow a consistent architecture pattern:
- Context Access -- Retrieves initialized SDK via
useNeroMpcAuthContext() - State Tracking -- Uses
useStateforisLoading,isConnecting,error - Memoization -- Implements
useCallbackfor returned functions - Error Handling -- Normalizes errors via try/catch/finally blocks
useNeroConnect
Primary entry point for user authentication with support for multiple login methods.
Return Interface
| Field | Type | Description |
|---|---|---|
connect | (provider: string, redirectUri: string) => Promise<void> | Initiates OAuth flow |
handleCallback | (provider: string, code: string, state: string, redirectUri: string) => Promise<void> | Processes OAuth redirect |
loginWithEmail | (email: string, type?: string) => Promise<void> | Starts email OTP/magic link flow |
verifyEmailLogin | (email: string, code: string) => Promise<void> | Completes email verification |
loginWithPhone | (phoneNumber: string) => Promise<void> | Initiates SMS OTP |
verifyPhoneLogin | (phoneNumber: string, code: string) => Promise<void> | Completes phone verification |
loginWithCustomJwt | (options: object) => Promise<void> | Authenticates with external JWT |
isConnecting | boolean | Indicates active authentication |
error | Error | null | Last authentication error |
useNeroSession
Manages existing authentication session lifecycle.
Return Interface
| Field | Type | Description |
|---|---|---|
getStatus | () => Promise<SessionStatus> | Fetches current session state |
reconnect | (dappShare?: string) => Promise<void> | Restores session from local/provided shares |
revoke | () => Promise<void> | Terminates session and logs user out |
status | SessionStatus | Cached session status |
isLoading | boolean | Indicates active operations |
useNeroWallet
Provides wallet generation and message signing capabilities.
Return Interface
| Field | Type | Description |
|---|---|---|
wallet | WalletInfo | null | Current wallet information; null if not generated |
hasWallet | boolean | Indicates existing key share for current user |
generateWallet | () => Promise<WalletInfo> | Triggers MPC key generation protocol |
signMessage | (message: string) => Promise<string> | Signs Ethereum personal messages |
signTypedData | (domain: object, types: object, primaryType: string, value: object) => Promise<string> | Signs EIP-712 typed data |
isGenerating | boolean | Loading state during wallet generation |
isSigning | boolean | Loading state during signing operations |
error | Error | null | Last operation error; reset at operation start |
State Management
Derived State (from context):
walletandhasWalletderive from the shared SDK state, not local state- Updated automatically when the SDK emits authentication or connection events
Local State:
isGenerating,isSigning, anderrorare managed viauseState
Operation Details
generateWallet() -- Initiates MPC key generation. Throws synchronously if SDK is uninitialized. Sets isGenerating to true, resets error to null, and always clears the loading flag in finally block.
signMessage(message) -- Signs arbitrary strings using Ethereum personal signing prefix. Requires both SDK and existing wallet. Throws "Wallet not available" if preconditions are not met, without entering loading state.
signTypedData(domain, types, primaryType, value) -- Signs EIP-712 typed data. Accepts domain struct, type definitions map, primary type name, and message data. Returns hex signature string.
Memoization
The three operation callbacks use useCallback with dependencies on [sdk] for generateWallet and [sdk, state.hasWallet] for signing operations, ensuring stable references across renders.
Error Handling Strategy
All hooks follow a consistent four-step error propagation pattern:
- Caught within the hook's
useCallback - Normalized to standard Error object
- Stored in the hook's
errorstate for UI rendering - Re-thrown to allow component-level handling
All operations reset error to null at operation start, and loading flags are always reset in finally blocks.
SDK Initialization Guard
All hook methods verify SDK initialization before executing:
if (!sdk) throw new Error("SDK not initialized");This ensures hooks are only functional within a valid NeroMpcAuthProvider context.