Overview
TheuseLoading hook provides access to the global loading state managed by the LoadingProvider. Itβs used throughout the NJ Rajat Mahotsav application to control the loading screen display and coordinate animations.
This hook must be used within a component wrapped by
LoadingProvider. The provider is configured at the root layout level in the application.Import
Usage
Basic Usage
Loading Screen Implementation
Fromcomponents/atoms/loading-screen.tsx:11:
Coordinating Animations
Fromcomponents/organisms/landing-page.tsx:14:
Return Value
The hook returns an object with the following properties:Boolean indicating whether the application is in a loading state. When
true, the loading screen is displayed.Function to update the loading state. Pass
false to hide the loading screen and show the main application content.Parameters:value: Boolean to set the loading state
Provider Setup
TheLoadingProvider must wrap your application at a high level:
Implementation Details
Context Structure
The hook uses React Context to provide global state:Error Handling
The hook throws an error if used outside the provider:Use Cases
- Initial page load: Display loading screen while assets and data load
- User consent: Gate content behind audio permission or other user choices
- Animation coordination: Delay content animations until loading completes
- Route transitions: Show loading state during page navigation (with router integration)
Common Patterns
Audio Consent Flow
The most common pattern in the NJ Rajat Mahotsav app combines loading state with audio consent:- App starts with
isLoading: true - Loading screen displays with audio choice buttons
- User selects audio preference (Audio or Silent)
setIsLoading(false)is called- Loading screen animates out, main content animates in
Content Visibility
Use loading state to control when content becomes visible:Related
- Background Audio - Works together with loading for user consent
- Atoms - LoadingScreen component that uses this hook
