@youversion/platform-react-hooks package provides React hooks for seamless integration with the YouVersion Platform API. It offers data fetching hooks, authentication management, and reading session state management.
Architecture
The hooks package follows a three-layer architecture:- Providers: Context providers that manage configuration and state
- Data Hooks: Hooks that fetch and manage Bible data, languages, and highlights
- Utility Hooks: Helper hooks and functions for common operations
useApiData pattern, which provides:
- Automatic loading and error states
- Caching capability
- Refetch functionality
- Conditional fetching with the
enabledoption
Key Features
Unified Data Fetching Pattern
All data hooks return a consistent interface:Provider-Based Configuration
The SDK uses React Context to manage configuration and state:- YouVersionProvider: Core SDK configuration (required for all hooks)
- YouVersionAuthProvider: Authentication state management (lazy-loaded when auth is enabled)
- ReaderProvider: Bible reading session state
- VerseSelectionProvider: Multi-verse selection state
Type Safety
All hooks are fully typed with TypeScript, providing autocomplete and type checking for:- Hook parameters
- Return values
- Configuration options
- API responses
Installation
Quick Start
1. Setup Provider
Wrap your application withYouVersionProvider:
2. Use Data Hooks
Hook Categories
Providers
Context providers for configuration and state management
Data Hooks
Hooks for fetching Bible content, versions, and languages
Auth Hooks
Authentication and user management hooks
Utility Hooks
Helper hooks and utility functions
Core Concepts
Conditional Fetching
All data hooks support conditional fetching via theenabled option:
Manual Refetching
All data hooks provide arefetch function to manually trigger data updates:
Error Handling
All data hooks expose error states for graceful error handling:Dependencies
The hooks package depends on:@youversion/platform-core- Core API clients and typesreact^19.1.2 - React library
@youversion/platform-core and does not implement raw HTTP requests directly.
Best Practices
Always wrap your app with YouVersionProvider
Always wrap your app with YouVersionProvider
All hooks require
YouVersionProvider to be present in the component tree. Wrap your root component with the provider before using any hooks.Use conditional fetching to optimize performance
Use conditional fetching to optimize performance
Avoid unnecessary API calls by using the
enabled option:Handle loading and error states
Handle loading and error states
Always handle loading and error states for better UX:
Keep hooks UI-agnostic
Keep hooks UI-agnostic
Hooks should not return JSX or manipulate the DOM directly. They should only manage data and state:
Next Steps
Explore Providers
Learn about YouVersionProvider, ReaderProvider, and more
Browse Data Hooks
Discover hooks for Bible data, versions, and languages
Authentication
Implement user authentication with useYVAuth
Utilities
Explore helper hooks and utility functions
