The Gadget platform comes with application templates for our three main use cases: web apps, Shopify apps, and BigCommerce apps. Each template is designed to provide a starting point for your project, with the necessary configuration and boilerplate code to get you up and running quickly.
Base templates
Base templates are the very basic starting point for your project. They have boilerplate already setup for you, using what the Gadget team regards as best practices. They are designed to be a blank canvas for you to build upon.
The available base templates are:
Template
Tenancy
Framework
SSR/SPA
Shopify
Public
React
SPA
Shopify
Custom
React
SPA
Shopify
Public
Remix
SSR
Shopify
Custom
Remix
SSR
BigCommerce
Public
React
SPA
Web app
Multi-party auth
React Router v7
SSR
Web app
Single-party auth
React Router v7
SSR
Web app
No auth
React Router v7
SSR
SSR stands for server-side rendering, and SPA stands for single-page application.
Expanded templates
Apart from the base templates, we also have expanded templates. These templates are built on top of the base templates and include additional features and configurations. They are designed to provide a more complete starting point for your project.
You can find the expanded templates by following this link or on Github. You can also find the expanded templates from the app selection page. In the left nav, click on templates, and you will see the expanded templates.
React Router v7
Switching between SSR and SPA
This is only available when using the React Router v7 framework mode. You can switch between server-side rendering (SSR) and single-page application (SPA) mode by changing the React Router configs, adding the ssr flag set to false in the react-router.config file.
react-router.config.js
JavaScript
import type { Config } from "@react-router/dev/config";
import { reactRouterConfigOptions } from "gadget-server/react-router";
export default { ...reactRouterConfigOptions, ssr: false } satisfies Config;
import type { Config } from "@react-router/dev/config";
import { reactRouterConfigOptions } from "gadget-server/react-router";
export default { ...reactRouterConfigOptions, ssr: false } satisfies Config;
The clientLoader can be used in both SSR and SPA. For more information, take a look at the React Router
docs.
SPA mode
React
export async function clientLoader({ serverLoader }: Route.ClientLoaderArgs) {
// call the server loader (if using SSR)
const serverData = await serverLoader();
// And/or fetch data on the client
const data = getDataFromClient();
// Return the data to expose through useLoaderData()
return data;
}
export async function clientLoader({ serverLoader }: Route.ClientLoaderArgs) {
// call the server loader (if using SSR)
const serverData = await serverLoader();
// And/or fetch data on the client
const data = getDataFromClient();
// Return the data to expose through useLoaderData()
return data;
}
Make sure that you also switch any usage of the gadgetConfig, loaded in the loader when using SSR, to window.gadgetConfig when using SPA mode. You can do that by first adding the following script tag to the head tag in your root.tsx file:
web/root.jsx
React
export const Layout = ({ children }: { children: React.ReactNode }) => {
return (
<html lang="en">
<head>
<Meta />
{/* This script tag injects the gadgetConfig object in the window */}
<script suppressHydrationWarning>/* --GADGET_CONFIG-- */</script>
<Links />
</head>
<body>
<Suspense fallback={<div>Loading...</div>}>{children}</Suspense>
<ScrollRestoration />
<Scripts />
</body>
</html>
);
};
export const Layout = ({ children }: { children: React.ReactNode }) => {
return (
<html lang="en">
<head>
<Meta />
{/* This script tag injects the gadgetConfig object in the window */}
<script suppressHydrationWarning>/* --GADGET_CONFIG-- */</script>
<Links />
</head>
<body>
<Suspense fallback={<div>Loading...</div>}>{children}</Suspense>
<ScrollRestoration />
<Scripts />
</body>
</html>
);
};
Then switch any usage of the gadgetConfig to window.gadgetConfig in your components.
Switching between framework and declarative mode
To switch your React Router v7 mode to declarative mode, you need to add an index.html file to the root of your project, including the following code:
You'll need to add a main.tsx file to the web folder and add the following code:
web/main.jsx
React
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./components/App";
const root = document.getElementById("root");
if (!root) throw new Error("#root element not found for booting react app");
ReactDOM.createRoot(root).render(
<React.StrictMode>
<App />
</React.StrictMode>
);
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./components/App";
const root = document.getElementById("root");
if (!root) throw new Error("#root element not found for booting react app");
ReactDOM.createRoot(root).render(
<React.StrictMode>
<App />
</React.StrictMode>
);
You will then need to add the App.tsx file that includes a browser router:
SPA mode does not support the loader and action functions. You need to use Gadget's React hooks and autocomponents to read and write data in your frontend.
Switching from Remix to React Router v7
To switch from Remix to React Router v7, you need to add some packages and files to your application.