React Router (Remix) quickstart

Displaying content in a React Router front end

You’ve configured your Studio with a post document type and learned how to query from your hosted dataset. Before deploying the Studio, let’s query and display this content on the front-end framework of your choice.

1Install a new React Router 7 (Remix) application

If you have an existing application, skip this first step and adapt the rest of the lesson to install Sanity dependencies to fetch and render content.

Run the following in a new tab or window in your Terminal (keep the Studio running) to create a new React Router 7 application with Tailwind CSS and TypeScript.

You should now have your Studio and React Router 7 application in two separate, adjacent folders:

2Install Sanity dependencies

Run the following inside the react-router-hello-world directory to install:

3Start the development server

Run the following command and open http://localhost:5173 in your browser.

4Configure the Sanity client

To fetch content from Sanity, you’ll first need to configure a Sanity Client.

Create a directory react-router-hello-world/app/sanity and within it create a client.ts file, with the following code:

5Display content on the home page

React Router uses a loader function exported from routes for server-side fetching of data. Routes are configured in the app/routes.ts file.

The default home page can be found at app/routes/home.tsx

Update it to render a list of posts fetched from your Sanity dataset using the code below.

6Display individual posts

Create a new route for individual post pages.

The dynamic value of a slug when visiting /:post in the URL is used as a parameter in the GROQ query used by Sanity Client.

Notice that we’re using Tailwind CSS Typography’s prose class name to style the post’s body block content. Install it in your project following their documentation.

Update the routes.ts configuration file to load this route when individual post links are clicked.

Was this page helpful?