Remix Client Hints

screenshot of Remix Client Hints
react
remix
tailwind

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

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.

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.

react
React

React is a widely used JavaScript library for building user interfaces and single-page applications. It follows a component-based architecture and uses a virtual DOM to efficiently update and render UI components

remix
Remix

Remix is a modern JavaScript framework that focuses on building fast and performant web applications. It emphasizes a combination of server-rendered content and client-side interactivity, offering a robust architecture for creating scalable and maintainable projects.

tailwind
Tailwind

Tailwind CSS is a utility-first CSS framework that provides pre-defined classes for building responsive and customizable user interfaces.

eslint
Eslint

ESLint is a linter for JavaScript that analyzes code to detect and report on potential problems and errors, as well as enforce consistent code style and best practices, helping developers to write cleaner, more maintainable code.

framer-motion
Framer Motion

Alpine.js is a lightweight JavaScript framework that simplifies the process of creating dynamic, reactive user interfaces on the web. It uses a declarative syntax that offers a higher level of abstraction compared to vanilla JavaScript, while being more performant and easier to use than jQuery.

typescript
Typescript

TypeScript is a superset of JavaScript, providing optional static typing, classes, interfaces, and other features that help developers write more maintainable and scalable code. TypeScript's static typing system can catch errors at compile-time, making it easier to build and maintain large applications.

zod
Zod

Zod is a TypeScript-first schema declaration and validation library. It allows you to define schemas that can validate data at runtime while providing excellent TypeScript inference, making it perfect for API validation, form validation, and type-safe data handling.