Next Dark Mode

screenshot of Next Dark Mode
nextjs
react
styled-components

Enable dark mode for Next.js apps

Overview

next-dark-mode is a theme for Next.js apps that allows users to switch between a dark and light mode. It also includes an auto mode feature that automatically adjusts the theme based on the user's operating system preferences. The theme uses configurable cookies to persist the theme state, preventing any page load glitches.

Features

  • Auto mode: Supports automatic theme switching based on the user's operating system preferences.
  • No page load glitch: Uses configurable cookies to persist the theme state, avoiding common page load glitches.
  • Compatibility: Requires react@16.8.0 or higher, which includes Hooks.

Usage

To use next-dark-mode in your Next.js app, follow these steps:

  1. Wrap your _app.js component located in /pages with the HOC withDarkMode.
  2. Use the useDarkMode hook in your app to access the current theme.

If you are using CSS-in-JS libraries like emotion or styled-components, follow these additional steps:

  1. Wrap your _app.js component located in /pages with the HOC withDarkMode.
nextjs
Next.js

Next.js is a React-based web framework that enables server-side rendering, static site generation, and other powerful features for building modern web applications.

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

styled-components
Styled Components

Styled Components is a popular library for styling React components using CSS syntax. It allows you to write CSS in your JavaScript code, making it easier to create dynamic styles that are specific to each component.

template
Templates & Themes

A template or theme refers to a pre-designed layout or structure that provides a basic framework for building a specific type of application or website. It typically includes good design, placeholder content and functional features, allowing developers to customize and fill in the details according to their specific needs.

Dark Mode

Dark mode is a user interface option that uses a dark color scheme instead of light. It reduces eye strain and improves visibility in low-light conditions. Implementing dark mode in a website or application involves updating the styles and color palette to support both light and dark modes.

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.

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.