Skip to main content
Page components are React components that render on specific pages of your EverShop store. They’re used in both extensions (for functionality) and themes (for design) to build dynamic, data-driven user interfaces.

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:
  1. Default export - The React component function
  2. layout export - Placement configuration (area, order)
  3. 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

The layout export controls where and when your component renders:

Common Areas

Sort Order: Use increments of 10 (10, 20, 30) to allow inserting components in between later.

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

Performance: Only query the data you need. Avoid fetching unnecessary fields.
  • 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

  1. Verify layout export exists
  2. Check areaId is valid for the page
  3. Ensure component is in correct directory
  4. Run npm run build to recompile

Props Are Undefined

  1. Verify GraphQL query syntax
  2. Check field names match schema
  3. Ensure query returns data
  4. Add null checks with optional chaining

Styles Not Applying

  1. Verify Tailwind class names
  2. Check for typos
  3. Use bracket notation for custom colors
  4. Clear browser cache

Next Steps

Creating Themes

Learn about theme architecture

GraphQL Reference

Explore the GraphQL schema