NERO
API Reference

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:

  1. Context Access -- Retrieves initialized SDK via useNeroMpcAuthContext()
  2. State Tracking -- Uses useState for isLoading, isConnecting, error
  3. Memoization -- Implements useCallback for returned functions
  4. Error Handling -- Normalizes errors via try/catch/finally blocks

useNeroConnect

Primary entry point for user authentication with support for multiple login methods.

Return Interface

FieldTypeDescription
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
isConnectingbooleanIndicates active authentication
errorError | nullLast authentication error

useNeroSession

Manages existing authentication session lifecycle.

Return Interface

FieldTypeDescription
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
statusSessionStatusCached session status
isLoadingbooleanIndicates active operations

useNeroWallet

Provides wallet generation and message signing capabilities.

Return Interface

FieldTypeDescription
walletWalletInfo | nullCurrent wallet information; null if not generated
hasWalletbooleanIndicates 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
isGeneratingbooleanLoading state during wallet generation
isSigningbooleanLoading state during signing operations
errorError | nullLast operation error; reset at operation start

State Management

Derived State (from context):

  • wallet and hasWallet derive from the shared SDK state, not local state
  • Updated automatically when the SDK emits authentication or connection events

Local State:

  • isGenerating, isSigning, and error are managed via useState

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:

  1. Caught within the hook's useCallback
  2. Normalized to standard Error object
  3. Stored in the hook's error state for UI rendering
  4. 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.

On this page