Overview
Crocante provides a collection of custom React hooks for common functionality. These hooks encapsulate complex logic and make it reusable across components.useModal
Manage modal open/close state with lifecycle callbacks.Signature
Usage
Features
- Lifecycle Callbacks: Execute code on open/close
- Toggle Function: Toggle state programmatically
- Initial State: Set initial open state
- Previous Callbacks: Execute before state change
useSessionExpiry
Handle session expiration warnings and renewal.Signature
Usage
Features
- Automatic Warning: Shows modal before session expires
- Countdown: Tracks time until expiration
- Renewal: Extends session via API call
- Auto-trigger Auth: Opens login modal on expiration
useTokenConversion
Convert token amounts to/from USD with real-time rates.Signature
Usage
Features
- Real-time Rates: Polls conversion rates at intervals
- Bidirectional: Convert to and from USD
- Formatting: Automatic decimal precision
- Error Handling: Returns “0” for invalid inputs
useTokenSwap
Calculate token swap conversions with fees.Signature
Usage
Features
- Live Quotes: Real-time swap rates
- Commission Info: Fee percentages
- Minimum Amount: Enforced swap minimums
- Bidirectional: Calculate both directions
useSelector
Manage select dropdown state with change callbacks.Signature
Usage
Features
- Auto-reset: Resets when options change
- Change Callbacks: React to selection changes
- Get Next: Cycle through options
- Type-safe: Fully generic TypeScript support
useIsMobile
Detect mobile viewport with customizable breakpoint.Signature
Usage
Features
- SSR-safe: Prevents hydration mismatches
- Custom Breakpoints: Configure viewport threshold
- Resize Listener: Updates on window resize
- Performance: Efficient event listener cleanup
useMounted
Detect when component has mounted on client.Signature
Usage
Features
- SSR Compatible: Returns false on server
- Hydration Safe: Prevents mismatches
- Simple API: Boolean return value
useValueVerifier
Validate input values against constraints.Location
hooks/use-value-verifier.ts
Usage Context
Used internally for validating numeric inputs, checking minimum/maximum values, and ensuring input constraints are met.useSessionMode
Manage session operation modes.Location
hooks/use-session-mode.ts
Usage Context
Handles different session states and modes for user authentication flows.useTableFilters
Manages table filtering state, including filter modal, active filters display, and pagination reset.Signature
Parameters
- page: Current page number
- selectors: Array of selector configurations for filter dropdowns
- resetSelectors: Function to reset all selectors to default state
- setFilters: Callback to update the applied filters
- handleChangeFilters: Trigger object for filter changes
Return Value
- page: Synchronized page number (resets to 1 when filters change)
- filtersClassName: CSS class for filter button styling (
"secondary"or"outline") - activeFilters: Formatted string of active filter labels
- openFiltersModal: Function to open the filters modal
- filtersModalOpen: Boolean indicating if filters modal is open
- closeFiltersModal: Function to close the filters modal
Example
Behavior
- Filter Application: When selectors change, filters are automatically applied
- Page Reset: Page resets to 1 whenever filters change
- Visual Feedback: Filter button changes from
"secondary"to"outline"when filters are active - Active Filter Display: Shows comma-separated list of active filter labels
- Modal Management: Opens/closes filter modal with automatic reset on open
Use Cases
- Activity transaction filtering by status and type
- Loan history filtering by loan type and date range
- Staking position filtering by currency and status
- Any table that needs multiple filter criteria
Next Steps
Context Providers
Learn about context providers
UI Components
Explore UI components
