Home >Web Front-end >JS Tutorial >Setting Up Themes in SSR React Applications
Imagine visiting a website that seamlessly adapts to your preferences—effortlessly switching between light, dark and system-based themes.
This article continues my series on SSR with React. In the basics article, we explored production-ready configurations, while in advanced techniques, we tackled challenges like hydration errors. Now, we’ll take it a step further by implementing robust theming support that integrates seamlessly with SSR.
The main issue is the Initial Flash of Incorrect Theme (FOIT).
Essentially, themes are just about changing CSS variables. In most cases, you’ll work with three themes:
By default, the server will render the HTML with the light theme and send it to the browser. If a user prefers the dark theme, they will see a visible theme change on the first page load, which disrupts the user experience.
There are two main ways to solve this issue: