Remix Client Hints screenshot

Remix Client Hints

Author Avatar Theme by Dev xo
Updated: 16 Oct 2023
21 Stars

An intuitive Remix + Client Hints example, that provides Theme Switching & Server Dates in your application.

Categories

Overview

This article provides an example of implementing theme switching and server dates using Epic Stack - Client Hints and Jacob Paris’ article as a reference. The example demonstrates how the server retrieves theme and time-zone hints on the first visit, stores them in cookies, and reloads the page for client-side usage. The approach aims to improve user experience by avoiding the flash of unstyled content on every page load.

Features

  • Theme Switching: Implements theme switching based on the prefers-color-scheme media feature. It updates the theme cookie through a POST request to the /resources/theme route and either reloads the page or returns a JSON response.
  • Time-Zone: Allows the server to understand the client’s time zone on initial page load. The server-side implementation uses the getHints(request).timeZone method to retrieve time zone information. For client-side usage, the useHints().timeZone method can be employed.
  • UI Display: The App Demo displays the time zone in the user interface using the Intl.DateTimeFormat object created in the user’s time zone and preferred language.

Installation

To run this example locally, follow these steps:

  1. Clone the repository.
  2. Install the dependencies.
  3. Run the server.

Summary

This article provides a practical example of implementing theme switching and server dates using Epic Stack - Client Hints. It explains how the server retrieves theme and time-zone hints, stores them in cookies, and reloads the page for client-side usage. The article also provides resources for further understanding of Client Hints and the implementation discussed. Contributions are welcome, and the example is licensed under the MIT license.