Overview
Page components in EverShop:- Are React components with TypeScript support
- Use a component area system to control placement
- Fetch data via GraphQL queries
- Support server-side rendering for better performance and SEO
- Can be page-specific or global across all pages
Component Structure
Every page component must export three things:- Default export - The React component function
- layout export - Placement configuration (area, order)
- query export (optional) - GraphQL query for data
Basic Template
Directory Organization
Page components are organized by scope:Scope Hierarchy
- all/ - Renders on every page
- frontStore/ - Renders on all front-end pages
- admin/ - Renders on all admin pages
- [page-name]/ - Renders on specific page only
Real-World Examples
Simple List Component
Here’s a complete example from the sample extension:extensions/sample/src/pages/frontStore/homepage/FooList.tsx
Header Component
A global header component from the anasuplements theme:themes/anasuplements/src/pages/all/Header.tsx
Product Page Component
A component that displays product information:extensions/productCatalog/src/pages/frontStore/productView/SupplementInfo.tsx
Layout Configuration
Thelayout export controls where and when your component renders:
Common Areas
Custom Areas
You can also create custom areas in your components:Working with GraphQL
Basic Query
Query with Parameters
Use context values for dynamic data:Nested Data
Fetch related data:Props are automatically passed to your component based on the GraphQL query results.
TypeScript Types
Always define types for your props:Conditional Rendering
Null Checks
Conditional Content
Styling Components
Use Tailwind CSS for styling:Responsive Grid
Hover Effects
Custom Colors
Best Practices
- Type Safety - Always define TypeScript types for props
- Null Checks - Use optional chaining (
?.) for nested data - Semantic HTML - Use proper HTML elements (
<header>,<nav>,<article>) - Accessibility - Add ARIA labels and proper alt text
- Responsive - Design mobile-first with Tailwind breakpoints
- Performance - Optimize images and minimize re-renders
Common Patterns
List with Empty State
Loading State
Error Boundaries
Troubleshooting
Component Not Rendering
- Verify
layoutexport exists - Check
areaIdis valid for the page - Ensure component is in correct directory
- Run
npm run buildto recompile
Props Are Undefined
- Verify GraphQL query syntax
- Check field names match schema
- Ensure query returns data
- Add null checks with optional chaining
Styles Not Applying
- Verify Tailwind class names
- Check for typos
- Use bracket notation for custom colors
- Clear browser cache
Next Steps
Creating Themes
Learn about theme architecture
GraphQL Reference
Explore the GraphQL schema