Convert Figma logo to code with AI

Shopify logohydrogen

Hydrogen lets you build faster headless storefronts in less time, on Shopify.

1,394
267
1,394
128

Top Related Projects

11,294

Next.js Commerce

24,996

Building blocks for digital commerce

A customizable, open-source ecommerce platform built on WordPress. Build any commerce solution you can imagine.

12,911

An open source eCommerce platform giving you full control and customizability. Modular and API-first. Build any eCommerce solution that your business requires. Developed by @vendo-dev

Quick Overview

Shopify Hydrogen is an open-source React-based framework for building custom storefronts on Shopify. It provides a set of tools, components, and utilities to create fast, dynamic, and customizable e-commerce experiences using React Server Components and Shopify's APIs.

Pros

  • Built on React Server Components, offering improved performance and SEO
  • Seamless integration with Shopify's ecosystem and APIs
  • Provides pre-built components and hooks for common e-commerce functionalities
  • Supports both server-side rendering and static site generation

Cons

  • Relatively new framework, still evolving and may have some stability issues
  • Limited community resources and third-party integrations compared to more established frameworks
  • Learning curve for developers unfamiliar with React Server Components
  • Tied to Shopify's ecosystem, which may limit flexibility for non-Shopify use cases

Code Examples

  1. Fetching and displaying a product:
import {useShopQuery, gql, useRouteParams, Link, Image} from '@shopify/hydrogen';

export default function Product() {
  const {handle} = useRouteParams();
  const {data} = useShopQuery({
    query: PRODUCT_QUERY,
    variables: {
      handle,
    },
  });

  const product = data.product;

  return (
    <div>
      <h1>{product.title}</h1>
      <Image data={product.featuredImage} />
      <p>{product.description}</p>
      <Link to={`/products/${product.handle}`}>View Details</Link>
    </div>
  );
}

const PRODUCT_QUERY = gql`
  query Product($handle: String!) {
    product(handle: $handle) {
      title
      description
      featuredImage {
        url
        altText
        width
        height
      }
    }
  }
`;
  1. Creating a custom cart component:
import {useCart} from '@shopify/hydrogen';

export function Cart() {
  const {lines, cost, checkoutUrl} = useCart();

  return (
    <div>
      <h2>Cart</h2>
      {lines.map((line) => (
        <CartItem key={line.id} {...line} />
      ))}
      <p>Total: {cost.totalAmount.amount}</p>
      <a href={checkoutUrl}>Checkout</a>
    </div>
  );
}

function CartItem({merchandise, quantity}) {
  return (
    <div>
      <p>{merchandise.product.title}</p>
      <p>Quantity: {quantity}</p>
      <p>Price: {merchandise.priceV2.amount}</p>
    </div>
  );
}
  1. Adding a product to the cart:
import {useCart} from '@shopify/hydrogen';

export function AddToCartButton({variantId}) {
  const {linesAdd} = useCart();

  const addToCart = () => {
    linesAdd([{merchandiseId: variantId, quantity: 1}]);
  };

  return <button onClick={addToCart}>Add to Cart</button>;
}

Getting Started

To create a new Hydrogen project:

npm create @shopify/hydrogen@latest

# Follow the prompts to set up your project

cd your-project-name
npm install
npm run dev

This will set up a new Hydrogen project and start the development server. You can then begin building your custom storefront using Hydrogen's components and APIs.

Competitor Comparisons

11,294

Next.js Commerce

Pros of Commerce

  • More flexible and customizable, allowing for integration with various headless CMS and e-commerce platforms
  • Supports multiple payment providers out of the box
  • Easier to deploy and manage with Vercel's platform

Cons of Commerce

  • Requires more setup and configuration compared to Hydrogen's streamlined approach
  • Less optimized for Shopify-specific features and integrations
  • May have a steeper learning curve for developers new to Next.js or React

Code Comparison

Hydrogen (React component):

export function Product() {
  const {handle} = useParams();
  const {product} = useShopQuery({query: PRODUCT_QUERY, variables: {handle}});
  return <h1>{product.title}</h1>;
}

Commerce (Next.js page):

export default function Product({ product }) {
  return <h1>{product.name}</h1>;
}

export async function getStaticProps({ params }) {
  const product = await getProduct(params.slug);
  return { props: { product } };
}

Both repositories offer modern e-commerce solutions, but they cater to different needs. Hydrogen is tightly integrated with Shopify, providing a streamlined development experience for Shopify stores. Commerce, on the other hand, offers more flexibility and customization options, making it suitable for a wider range of e-commerce platforms and use cases.

24,996

Building blocks for digital commerce

Pros of Medusa

  • Open-source and self-hosted, offering more flexibility and customization
  • Modular architecture allows for easy extension and plugin development
  • Language-agnostic, supporting multiple programming languages for backend development

Cons of Medusa

  • Steeper learning curve for developers new to headless commerce
  • Smaller community and ecosystem compared to Shopify's established platform
  • Requires more setup and maintenance as a self-hosted solution

Code Comparison

Medusa (JavaScript):

const product = await medusaClient.products.retrieve("prod_01GDJGP2XPQT2N3JHZQFMH5V45")
console.log(product.title)

Hydrogen (React):

import {useShopQuery, gql} from '@shopify/hydrogen';

const {data} = useShopQuery({query: PRODUCT_QUERY});
console.log(data.product.title);

Both examples demonstrate retrieving product information, but Hydrogen leverages React hooks and GraphQL, while Medusa uses a more traditional client-server approach.

A customizable, open-source ecommerce platform built on WordPress. Build any commerce solution you can imagine.

Pros of WooCommerce

  • More extensive ecosystem with a wide range of plugins and themes
  • Greater flexibility and customization options for developers
  • Self-hosted solution, offering full control over data and infrastructure

Cons of WooCommerce

  • Requires more technical knowledge to set up and maintain
  • Performance can be slower, especially for larger stores
  • Security management is the responsibility of the store owner

Code Comparison

WooCommerce (PHP):

add_action('woocommerce_before_main_content', 'woocommerce_output_content_wrapper', 10);
add_action('woocommerce_after_main_content', 'woocommerce_output_content_wrapper_end', 10);

Hydrogen (React):

import {ShopifyProvider} from '@shopify/hydrogen-react';

function App() {
  return (
    <ShopifyProvider shopifyConfig={/* ... */}>
      {/* Your app components */}
    </ShopifyProvider>
  );
}

WooCommerce uses WordPress hooks and actions for customization, while Hydrogen leverages React components and Shopify's API. WooCommerce offers more traditional server-side rendering, whereas Hydrogen focuses on modern, client-side rendering with server-side components for improved performance.

12,911

An open source eCommerce platform giving you full control and customizability. Modular and API-first. Build any eCommerce solution that your business requires. Developed by @vendo-dev

Pros of Spree

  • Open-source and self-hosted, offering more control and customization
  • Mature project with a large community and extensive ecosystem of extensions
  • Built on Ruby on Rails, leveraging its robust framework and conventions

Cons of Spree

  • Steeper learning curve, especially for developers not familiar with Ruby on Rails
  • Requires more setup and maintenance compared to Hydrogen's managed solution
  • May have higher hosting costs and infrastructure management overhead

Code Comparison

Spree (Ruby):

Spree::Config.configure do |config|
  config.use_static_preferences!
  config.currency = "USD"
  config.checkout_zone = "North America"
end

Hydrogen (React):

export default function App() {
  return (
    <ShopifyProvider shopifyConfig={shopifyConfig}>
      <CartProvider>
        <Router>
          {/* Your app components */}
        </Router>
      </CartProvider>
    </ShopifyProvider>
  );
}

The code snippets demonstrate the configuration approach for each platform. Spree uses Ruby for configuration, while Hydrogen utilizes React components and context providers for setup and state management.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Hydrogen Logo

MIT License npm downloads

📚 Docs | 💬 Discussions | 📝 Changelog

Hydrogen is Shopify’s stack for headless commerce. It provides a set of tools, utilities, and best-in-class examples for building dynamic and performant commerce applications. Hydrogen is designed to dovetail with Remix, Shopify’s full stack web framework, but it also provides a React library portable to other supporting frameworks.

Hydrogen Legacy v1

Hydrogen legacy v1 has been moved to a separate repo and the docs can be found here.

Getting started with Hydrogen

Requirements:

  • Node.js version 16.14.0 or higher
  • npm (or your package manager of choice, such as yarn or pnpm)
  1. Install the latest version of Hydrogen:

    npm create @shopify/hydrogen@latest
    
  2. Run the local development server:

    npm install
    npm run dev
    
  3. Open your new Hydrogen app running at http://localhost:3000.

See the complete Hydrogen docs.

Packages in this repo

Hydrogen is organized as a monorepo, which includes multiple packages that can be used together.

PackageLatest versionDescriptionReadme
@shopify/hydrogenLatest badgeOpinionated tools, utilities, and best-in-class examples for building a commerce application with Remix.Readme
@shopify/hydrogen-reactLatest badgeUnopionated and performant library of Shopify-specific commerce components, hooks, and utilities.Readme
@shopify/cli-hydrogenLatest badgeHydrogen extension for Shopify CLI.Readme
@shopify/create-hydrogenLatest badgeGenerate a new Hydrogen project from the command line.Readme
@shopify/hydrogen-codegenLatest badgeGenerate types for Storefront API queries automatically.Readme
@shopify/remix-oxygenLatest badgeRemix adapter enabling Hydrogen to run on the Oxygen runtime.Readme
@shopify/mini-oxygenLatest badgeA local runtime for Hydrogen apps that simulates the Oxygen production environment.Readme

Versioning

Hydrogen and hydrogen-react are tied to specific versions of the Shopify Storefront API, which follows calver.

For example, if you're using Storefront API version 2023-01, then Hydrogen and hydrogen-react versions 2022.1.x are fully compatible.

If the Storefront API version update includes breaking changes, then Hydrogen and hydrogen-react may also include breaking changes. Because the API version is updated every three months, breaking changes could occur every three months.

Learn more about API release schedules at Shopify.

Contributing to Hydrogen

Read our contributing guide

Other handy links

Learn more about Hydrogen.

NPM DownloadsLast 30 Days