# React Hooks for react-native-sensitive-info This document covers the React hooks API for `react-native-sensitive-info`, designed with modern React best practices including automatic cleanup, memory leak prevention, and performance optimization. ## Table of Contents - [Quick Start](#quick-start) - [Core Hooks](#core-hooks) - [Best Practices](#best-practices) - [Performance Considerations](#performance-considerations) - [Error Handling](#error-handling) - [Migration Guide](#migration-guide) - [Examples](#examples) ## Quick Start ### Installation ```bash npm install react-native-sensitive-info # or yarn add react-native-sensitive-info ``` ### Basic Usage ```tsx import { useSecretItem, useSecureStorage } from 'react-native-sensitive-info/hooks' function MyComponent() { // Read a single secret const { data, isLoading, error } = useSecretItem('apiToken') // Manage all secrets in a service const { items, saveSecret, removeSecret } = useSecureStorage({ service: 'myapp' }) if (isLoading) return Loading... if (error) return Error: {error.message} return {data?.value} } ``` ## Core Hooks ### `useSecretItem` Fetches and manages a single secure storage item with automatic loading and error states. #### API ```typescript function useSecretItem( key: string, options?: SensitiveInfoOptions & { includeValue?: boolean skip?: boolean } ): AsyncState & { refetch: () => Promise } interface AsyncState { data: TData | null error: HookError | null isLoading: boolean isPending: boolean } ``` #### Features - ✅ Automatic request cancellation on unmount - ✅ Memory leak prevention via cleanup - ✅ Conditional loading with `skip` parameter - ✅ Manual refetch support - ✅ Type-safe error handling #### Example ```tsx function TokenViewer() { const { data, isLoading, error, refetch } = useSecretItem('refreshToken', { service: 'auth', accessControl: 'secureEnclaveBiometry', authenticationPrompt: { title: 'Authenticate', description: 'Required to access your token' } }) if (isLoading) return if (error) return Failed to load token: {error.message} if (!data) return No token found return ( {data.value}