Building High-Performance Online Stores with Shopify Hydrogen and Remix

Rate this content
Bookmark

I. Introduction

- Overview of Shopify Hydrogen and Remix

- Importance of headless e-commerce and its impact on the industry


II. Setting up Shopify Hydrogen

- Installing and setting up Hydrogen with Remix

- Setting up the project structure and components


III. Creating Collections and Products

- Creating collections and products using Hydrogen’s React components

- Implementing a Shopping Cart

- Building a shopping cart using Hydrogen’s built-in components


VI. Building the home page with Storyblok

- Cloning the space and explaining how it works

- Implementing Storyblok in the repo

- Creating the Blok components

- Creating the Shopify components

- Implementing personalisation

This workshop has been presented at React Advanced 2023, check out the latest edition of this React Conference.

FAQ

The main topic discussed is the loop behind React, specifically focusing on the Hydrogen framework created by Shopify and its integration with Remix.

The collaborators mentioned are Spana and Omikasa.

Hydrogen is a framework created by Shopify. It is interesting because it integrates with Remix and is built on top of web standards, making it easier to use for developers.

Storyblok is used as a headless CMS with a visual editor that helps integrate commerce functionalities into the website.

The project personalizes the homepage based on user behavior by displaying different banners and product grids depending on the user's navigation and interactions with the website.

The .env file is used to store necessary tokens and environment variables required for the project, such as Shopify instance tokens.

The main features include a homepage with banners and product grids, individual product pages, a cart functionality with add to cart and remove from cart buttons, and personalized content based on user behavior.

The 'useLoaderData' hook in Remix is used to retrieve data from the server that is returned by the loader function, making it available to the components.

SEO is handled using a custom SEO component that sets the SEO title and meta description based on the data retrieved from the loader function.

The 'getStoryblokApi' function is used to initialize the connection with Storyblok, allowing the retrieval of content from the CMS and enabling the visual editor functionalities.

Alexandra Spalato
Alexandra Spalato
104 min
17 Oct, 2023

Comments

Sign in or register to post your comment.
Video Summary and Transcription
The Workshop covered various topics including building a homepage with Hydrogen and Storyblok, querying data using storefront.query and storefront.mutate, building collection indexes and details, adding items to the cart and displaying cart data, connecting Storyblok and adding a development server, setting up environments and creating page routes, using Storyblok and creating page components, personalizing the homepage based on user behavior, integrating Storyblok with Shopify components, and closing remarks.

1. Introduction to Hydrogen and Building the Homepage

Short description:

We are here today to introduce the __ loop behind React. Today, we are working with Spana and Omikasa to hear from them. Hydrogen is built on top of Remix with some packages and an integration of packages. The website we're going to build is the homepage, which is built with hydrogen and Storyblok. It includes a banner, a grid of products, and a single product. Personalization is introduced to display different information based on the customer's behavior. The workshop includes instructions on cloning the repo, creating the.env file, and running npm install.

We are here today to introduce the __ loop behind React. Today, we are working with Spana and Omikasa to hear from them. Before that, please join us in welcoming Omikasa. I wanted to give a talk about hydrogen because I think it's very interesting that Shopify create its own framework and when I begin with it, where we sell our components and then they bought Remix. And so I learned Remix because of hydrogen.

In the beginning, what is funny is I was not attracted to Remix because I'm more frontend and the food stag, etc. And I come from freelancing. Now, I am a dev rel at Storyblok. And what happens, I really fell in love with Remix because it makes everything easier because it's based on the web standards. And so my new talk in conferences is about web standards in Remix. So, it was a double win because I learned hydrogen and I found my favorite framework this way. So, basically, hydrogen is really built on top of Remix with some packages and an integration of packages. Sorry, I have to stop my notifications. The Shopify APIs.

So, let's begin. I'm going to share my screen. To begin, we have this Notion page where I have all the information, all I'm going to say, and all the code is there. So, this is the URL. So, please go there to follow up. It's a short URL, t.li slash hydrogen. Okay? And after that, you will clone this repository so you have the link on the Notion page. And while you're doing that, I'm going to show you the final website that we are going to build.

So this is the website that we're going to build. So this is your homepage. And the homepage is built with hydrogen but also with Storyblok, which is a headless CMS with a visual editor that has extension to integrate commerce in it. So here, first we have a banner, and here we have a grid of products. So these products are pulled from Shopify, but we can see them visually, you know, in the visual editor here. And then we have a single product. And this single product pulls this from Shopify, and this from the CMS, and everything is visual. So I'm going to show you also how this is built.

Now, if we go to find your board here, we are led to the entries for the Shopify connection. So we have a performance board and original board. So if we go to performance boards, here, we see all the collection details with all the Shopify products. So this is 100% Shopify and not Storyblok. And now I can go to my product details. Here I have a Buy Now button and Add to Cart button. So I add the cart, and you can see here's a number of items in my cart. And then if I go to the cart, I can check out. So it's a and I can also remove products. It's a functional, simple e-commerce. I took a free theme from Shopify and to copy the style and take inspiration to make this nice surf website. And now if I come back to the homepage, you can see that this banner has changed. Now it's featuring performance board. And this grid is only a performance board, too. And this is because I have introduced some personalization. I don't know if you heard about personalization, but it's really a high trend now in e-commerce. It means that depending on the behavior of the customer, we are going to display different information. So here, as I have navigated to the performance board, I assume that this user, me, is interested in performance board. So when it comes back to the website, I serve performance boards to drive sales, of course. So I will show you also how this is built in the back office with Storyblok and in the code and how all this works.

So now, I don't know if you have already cloned the repo? And also the notion page? When it's done, you create a.env file. I think there is perhaps a.env example. And here you have all the necessary tokens because I already have a Shopify instance and so you don't have to create it. And you have all the tokens so you will get all the products from there. So please raise your hand if it's not finished. So after that, you clone the repo here. So I will wait five minutes so everybody can do it. And then you run npm install. And after that you create the.env file. And you stay for the moment on the main branch and we are going to progress by branches. Okay, when you are ready, you just run npm run dev or h2dev works also, which is shortcuts. And you should have this. Okay. So I'm going to comment the repo. So to create this, I have create the comment with the comment lines by. So if we go to a hydrogen Shopify. And if we go to the docs, getting started, okay. If we run this command, I let you try this by yourself because last time I did a workshop in four hours and it was taking too much time. But if you run this command, you will have a full featured e-commerce with everything including user registration, search orders, everything you can find and with mock data. So from there you can explore or customize it.

2. Using the Hello World Template and Querying Data

Short description:

In this part, the speaker discusses using the Hello World template and building on top of it. They explain the basic structure of a remix and how to import layouts and wrap outlets. The speaker also introduces the use of storefront.query and storefront.mutate for getting and manipulating data. They mention some challenges with the Hello World template and suggest referring to the documentation. The speaker then guides the audience in creating a query to get the collection index and retrieving the necessary data in the component. They offer assistance and give instructions to try the exercise. The part concludes with a mention of the collections branch.

But in this case, I have used the Hello World template. I think it's another command, so here there is just tutorials that I recommend also if you want to work alone, I learned everything from there and the documentation is really well done. So, okay, let's show this, where is the Hello World command? I just wanted to show... Okay, I don't find a Hello World command now, but it's a basic template and I have built on top of this.

And here what I have already installed because we want to focus on Hydrogen and not on all the basic things. I have installed Tailwind. I also have created the basic things like your footer, okay. A header with just a logo and a menu with just a link to the collections named board and a layout. And so this is a remix. And in remix we have a root file which is the parent root. And so we import the layout here and we wrap our outlet. So the outlet will display the other routes. And so we wrap the layout here. And then we have the index root which is created by default. Here we have the end file. And server.js is our entry point. And this is when you use the Hello world template all this is created for you. So you have this function create store from client and you create the store front with it and it pass all these N variables here. Then it's best to get that context. And so it would be available in the global context of remixes, loaders and actions. So for the ones who don't know remixes it's a full stack framework and loader functions get data from the server and action functions create mutations on the server. So with the storefront, we will be able to make to get data with storefront.query and with storefront.query, we will get the data to create the collections, to create the products, to read the data from the cart and with storefront.mutate, we will perform GraphQL mutations to create the cart operations. Okay, and so everything is full stack, these functions happen on the server and they are the same file from the components where you load the data from the server. So all the components are full stack. So any questions about that? You're muted. I cannot hear you. Well, I'm fine. I'm already happy that I got the environment running, so. Okay. What I wanted to say also, yes, when you install the Hello World template, you don't have that. And so it was a few weeks ago I have to read this talk in Amsterdam. Yes, no, in Croatia, because I have this in Croatia. And what happens, it changed many things. And they had this new content security policy and nothing was working. So this is not the perfect way to do it. There is things in the documentation. So I make it in a quick way like that. Because of that, the image was not working. The scripts neither. So this is something I had on top of the template, just to know what is immediately available and what you have to create. OK, so if your template is working, your repo is working, let's go back to Notion. So now we are going to create the collection of N products. So this is what I was explaining, a storefront query and storefront mutate. We can do this exercise if you want. We can try. So if we go to localhost 3000 and slash GraphQL, we have access to the GraphQL schema. OK? So from there, we want to create a query to get the collection index. So in the collection index, what we have, we have the image from the collection. We have the title and we have a handle that links to the collection details. So we need all that. So we need to create this query. So we can create it in GraphQL. We can search there. Then we need to write it in the root. So I show you the root. Oops. We need to create a root for that. OK. So you can look into the documentation. I will let you have 15 minutes for that. And then we need to write a loader function to query the necessary data. So data from our collection. Then we need to retrieve this data in the component with use loader data hook, which is a hook from Remix to retrieve the data from the server. And then to write a component just to display a collection title. Perhaps it's a bit too much, if you don't know hydrogen, but do you want to try? Do you want the solution immediately? I will give it a try. OK, go! OK. So I'm going to explain because it will be easier. So for that, you go to the branch. To collections. This branch, no one, one collections.

Watch more workshops on topic

Remix Fundamentals
React Summit 2022React Summit 2022
136 min
Remix Fundamentals
Top Content
Featured WorkshopFree
Kent C. Dodds
Kent C. Dodds
Building modern web applications is riddled with complexity And that's only if you bother to deal with the problems
Tired of wiring up onSubmit to backend APIs and making sure your client-side cache stays up-to-date? Wouldn't it be cool to be able to use the global nature of CSS to your benefit, rather than find tools or conventions to avoid or work around it? And how would you like nested layouts with intelligent and performance optimized data management that just works™?
Remix solves some of these problems, and completely eliminates the rest. You don't even have to think about server cache management or global CSS namespace clashes. It's not that Remix has APIs to avoid these problems, they simply don't exist when you're using Remix. Oh, and you don't need that huge complex graphql client when you're using Remix. They've got you covered. Ready to build faster apps faster?
At the end of this workshop, you'll know how to:- Create Remix Routes- Style Remix applications- Load data in Remix loaders- Mutate data with forms and actions
Back to the Roots With Remix
React Summit 2023React Summit 2023
106 min
Back to the Roots With Remix
Featured Workshop
Alex Korzhikov
Pavlik Kiselev
2 authors
The modern web would be different without rich client-side applications supported by powerful frameworks: React, Angular, Vue, Lit, and many others. These frameworks rely on client-side JavaScript, which is their core. However, there are other approaches to rendering. One of them (quite old, by the way) is server-side rendering entirely without JavaScript. Let's find out if this is a good idea and how Remix can help us with it?
Prerequisites- Good understanding of JavaScript or TypeScript- It would help to have experience with React, Redux, Node.js and writing FrontEnd and BackEnd applications- Preinstall Node.js, npm- We prefer to use VSCode, but also cloud IDEs such as codesandbox (other IDEs are also ok)
How to Solve Real-World Problems with Remix
Remix Conf Europe 2022Remix Conf Europe 2022
195 min
How to Solve Real-World Problems with Remix
Featured Workshop
Michael Carter
Michael Carter
- Errors? How to render and log your server and client errorsa - When to return errors vs throwb - Setup logging service like Sentry, LogRocket, and Bugsnag- Forms? How to validate and handle multi-page formsa - Use zod to validate form data in your actionb - Step through multi-page forms without losing data- Stuck? How to patch bugs or missing features in Remix so you can move ona - Use patch-package to quickly fix your Remix installb - Show tool for managing multiple patches and cherry-pick open PRs- Users? How to handle multi-tenant apps with Prismaa - Determine tenant by host or by userb - Multiple database or single database/multiple schemasc - Ensures tenant data always separate from others
Build and Launch a personal blog using Remix and Vercel
Remix Conf Europe 2022Remix Conf Europe 2022
156 min
Build and Launch a personal blog using Remix and Vercel
Featured Workshop
Robert Pop
Robert Pop
In this workshop we will learn how to build a personal blog from scratch using Remix, TailwindCSS. The blog will be hosted on Vercel and all the content will be dynamically served from a separate GitHub repository. We will be using HTTP Caching for the blog posts.
What we want to achieve at the end of the workshop is to have a list of our blog posts displayed on the deployed version of the website, the ability to filter them and to read them individually.
Table of contents: - Setup a Remix Project with a predefined stack- Install additional dependencies- Read content from GiHub- Display Content from GitHub- Parse the content and load it within our app using mdx-bundler- Create separate blog post page to have them displayed standalone- Add filters on the initial list of blog posts
Building a Shopify App with React & Node
React Summit Remote Edition 2021React Summit Remote Edition 2021
87 min
Building a Shopify App with React & Node
Top Content
WorkshopFree
Jennifer Gray
Hanna Chen
2 authors
Shopify merchants have a diverse set of needs, and developers have a unique opportunity to meet those needs building apps. Building an app can be tough work but Shopify has created a set of tools and resources to help you build out a seamless app experience as quickly as possible. Get hands on experience building an embedded Shopify app using the Shopify App CLI, Polaris and Shopify App Bridge.We’ll show you how to create an app that accesses information from a development store and can run in your local environment.
Create a Visually Editable Next.js Website Using React Bricks, With Blog and E-commerce
React Summit 2023React Summit 2023
139 min
Create a Visually Editable Next.js Website Using React Bricks, With Blog and E-commerce
Top Content
WorkshopFree
Matteo Frana
Matteo Frana
- React Bricks: why we built it, what it is and how it works- Create a free account- Create a new project with Next.js and Tailwind- Explore the directory structure- Anatomy of a Brick- Create a new Brick (Text-Image)- Add a title and description with RichText visual editing- Add an Image with visual editing- Add Sidebar controls to edit props (padding and image side)- Nesting Bricks using the Repeater component- Create an Image gallery brick- Publish on Netlify or Vercel- Page Types and Custom fields- Access Page meta values- Internationalization- How to reuse content across pages: Stories and Embeds- How to create an E-commerce with Products’ data from an external database and landing pages created visually in React Bricks- Advanced enterprise features: flexible permissions, locked structure, custom visual components

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

Building Better Websites with Remix
React Summit Remote Edition 2021React Summit Remote Edition 2021
33 min
Building Better Websites with Remix
Top Content
Remix is a web framework built on React Router that focuses on web fundamentals, accessibility, performance, and flexibility. It delivers real HTML and SEO benefits, and allows for automatic updating of meta tags and styles. It provides features like login functionality, session management, and error handling. Remix is a server-rendered framework that can enhance sites with JavaScript but doesn't require it for basic functionality. It aims to create quality HTML-driven documents and is flexible for use with different web technologies and stacks.
Don't Solve Problems, Eliminate Them
React Advanced 2021React Advanced 2021
39 min
Don't Solve Problems, Eliminate Them
Top Content
Kent C. Dodds discusses the concept of problem elimination rather than just problem-solving. He introduces the idea of a problem tree and the importance of avoiding creating solutions prematurely. Kent uses examples like Tesla's electric engine and Remix framework to illustrate the benefits of problem elimination. He emphasizes the value of trade-offs and taking the easier path, as well as the need to constantly re-evaluate and change approaches to eliminate problems.
Scaling Up with Remix and Micro Frontends
Remix Conf Europe 2022Remix Conf Europe 2022
23 min
Scaling Up with Remix and Micro Frontends
Top Content
This talk discusses the usage of Microfrontends in Remix and introduces the Tiny Frontend library. Kazoo, a used car buying platform, follows a domain-driven design approach and encountered issues with granular slicing. Tiny Frontend aims to solve the slicing problem and promotes type safety and compatibility of shared dependencies. The speaker demonstrates how Tiny Frontend works with server-side rendering and how Remix can consume and update components without redeploying the app. The talk also explores the usage of micro frontends and the future support for Webpack Module Federation in Remix.
Full Stack Components
Remix Conf Europe 2022Remix Conf Europe 2022
37 min
Full Stack Components
Top Content
RemixConf EU discussed full stack components and their benefits, such as marrying the backend and UI in the same file. The talk demonstrated the implementation of a combo box with search functionality using Remix and the Downshift library. It also highlighted the ease of creating resource routes in Remix and the importance of code organization and maintainability in full stack components. The speaker expressed gratitude towards the audience and discussed the future of Remix, including its acquisition by Shopify and the potential for collaboration with Hydrogen.
Remix Flat Routes – An Evolution in Routing
Remix Conf Europe 2022Remix Conf Europe 2022
16 min
Remix Flat Routes – An Evolution in Routing
Top Content
Remix Flat Routes is a new convention that aims to make it easier to see and organize the routes in your app. It allows for the co-location of support files with routes, decreases refactor and redesign friction, and helps apps migrate to Remix. Flat Folders convention supports co-location and allows importing assets as relative imports. To migrate existing apps to Flat Routes, use the Remix Flat Routes package's migration tool.
How React Router Became a Framework
React Advanced 2024React Advanced 2024
31 min
How React Router Became a Framework
My name is Mark Dalglish and I'm here to discuss how ReactRouter became a framework. Remix is built on ReactRouter and heavily relies on it. Remix feels like a framework because it has a CLI, manages the dev and build lifecycle, and has strong opinions about the file system structure. Remix embraced Vite as a plugin, allowing developers to integrate it seamlessly into their existing Vite setup. The shift to Vite led to a change in the philosophy of Remix Vite, enabling frameworks to orchestrate all the environment builds and make the framework as a plugin pattern first class. React Router is merging with Remix to make all the build time framework features available to React Router consumers. React Router is now officially a framework as well as a library. The move to integrate Remix into React Router is driven by the exploration of the next generation of Remix. React Router V7 simplifies by dropping the React Native layer and allows flexibility for consumers to use it as a library or as a framework with additional architectural features provided by plugins. The focus is on betting on Vite in the long term, and React Router plans to support React Server components. Thank you to Mark for answering the questions.