Overview
TheHomeHeader component serves as the header section for the home screen. It integrates the SearchBar component with the application’s FilterContext to enable global search and filtering functionality across the cryptocurrency list.
This component acts as a bridge between the UI (SearchBar) and the application state (FilterContext), automatically passing filter updates to the context for consumption by other components.
Props
This component does not accept any props. It manages filtering through theFilterContext.
Usage Example
Basic Usage
With Safe Area
Complete Screen Layout
Component Architecture
Context Integration
The component uses theFilterContext to manage global filter state:
- Retrieves
setFilterfunction from FilterContext - Passes
setFilterdirectly to SearchBar’sonSearchprop - No local state management needed
- Filter updates are automatically propagated to all context consumers
Filter Context Requirements
This component expects aFilterContext provider to be present in the component tree:
Component Flow
Styling Details
Header Container
- Background: White (
#fff) for clean header appearance - Padding: 16px horizontal and top padding for spacing
- Border: 1px light gray bottom border (
#eee) for subtle separation - Shadow: Very subtle shadow for minimal elevation effect
- iOS:
shadowOpacity: 0.04with 3px radius - Android:
elevation: 2
- iOS:
Layout Structure
FilterContext API
Hook Interface
Usage in Other Components
Design Patterns
- Composition
- Context Pattern
- Container/Presenter
The HomeHeader demonstrates component composition by wrapping SearchBar:
- Separation of concerns: SearchBar handles UI, HomeHeader handles integration
- Reusability: SearchBar can be used elsewhere with different callbacks
- Flexibility: Easy to swap SearchBar implementation or add additional header elements
Related Components
- SearchBar: The search input component integrated by HomeHeader
- CryptoList: List component that consumes filter from context
- CryptoCard: Individual card component displayed in filtered list
Source Code Location
~/workspace/source/src/components/HomeHeader.tsx:17