Overview
The CustomHeader component provides a centered page header with a title and optional description. It’s a shared component used across multiple projects for consistent page headers. Location:gifs-app/src/shared/components/CustomHeader.tsx
Props
The main heading text displayed in an
<h1> tagOptional description text displayed below the title in a
<p> tag. Only rendered if provided.Features
- Minimal Design: Simple, focused component with no complex logic
- Conditional Rendering: Description only renders when provided
- Centered Layout: Uses
content-centerCSS class for alignment - TypeScript Support: Fully typed props interface
- Semantic HTML: Uses proper heading hierarchy
Usage Example
- With Description
- Title Only
Implementation
TypeScript Interface
Component Design Pattern
This component demonstrates several React best practices:1. Conditional Rendering
The description is only rendered when provided:description is falsy (undefined, null, or empty string), the <p> tag is not rendered.
2. Optional Props
The? in TypeScript makes the description prop optional:
3. Named Export
Uses named export for better tree-shaking and explicit imports:4. Prop Destructuring
Destructures props directly in the function parameters:Common Use Cases
Page Headers
Page Headers
Use as the main header for application pages:
Section Headers
Section Headers
Use to introduce major sections without description:
Landing Pages
Landing Pages
Use with longer descriptions for landing pages:
Empty States
Empty States
Use to explain empty states in applications:
Customization
Styling
The component uses acontent-center CSS class, which you can customize:
Extending the Component
You can extend this component with additional features:Testing
The component has an associated test file atCustomHeader.test.tsx:1. Here’s an example test pattern:
Related Components
SearchBar
Often used directly below CustomHeader
Component Overview
See all available components
Best Practices
Keep titles concise and descriptive (2-5 words)
Use descriptions to provide context or instructions
Ensure the component hierarchy uses h1 only once per page
Consider responsive font sizes for mobile devices
Use semantic HTML for better SEO and accessibility