Overview
useFlashListContext is a hook that provides access to the FlashList context, allowing child components to interact with their parent FlashList instance. This is useful when you need to trigger layout recalculations, access the list ref, or interact with parent/child scroll views.
This hook is particularly valuable when building complex nested list scenarios or when you need to coordinate between a list item and its parent list.
Type Signature
Parameters
This hook takes no parameters.Returns
Returns a context object if the component is rendered within a FlashList, otherwise returns
undefined.When to Use
UseuseFlashListContext when you need to:
- Manually trigger layout recalculation from within list items
- Access the FlashList ref from child components
- Coordinate scrolling between nested lists
- Implement custom scroll behaviors
- Build advanced nested list scenarios
- Check if a component is rendered within a FlashList
Basic Usage
Manual Layout Trigger
Accessing List Ref
Checking if Within FlashList
Real-World Examples
Dynamic Content with Layout Updates
Nested List Coordination
Scroll to Sibling Item
Custom Pull-to-Refresh Indicator
Accessing Parent Scroll View
Advanced Use Cases
Coordinating Multiple Nested Lists
Best Practices
Comparison with useLayoutState
| Feature | useFlashListContext | useLayoutState |
|---|---|---|
| Access to list ref | ✓ | ✗ |
| Manual layout trigger | ✓ | ✗ |
| State management | ✗ | ✓ |
| Auto layout on change | ✗ | ✓ |
| Access parent ref | ✓ | ✗ |
useFlashListContext when you need direct access to the list instance. Use useLayoutState when you need state management with automatic layout triggers.
Internal Context Structure
The context provides access to:- Current FlashList: Direct access to the immediate parent list
- Parent FlashList: Access to the grandparent list (for nested scenarios)
- Scroll Views: Both current and parent scroll view refs
- Layout Control: Method to trigger layout recalculation
Related Hooks
- useLayoutState - State management with automatic layout recalculation
- useRecyclingState - State management with auto-reset for recycled items
- useMappingHelper - Optimize mapped components in list items
Related APIs
- FlashListRef - FlashList ref methods
- FlashList Props - FlashList configuration options