1. @hakuna-matata-ui/color-mode
React component and hooks for handling light and dark mode.
@hakuna-matata-ui/color-mode
Package: @hakuna-matata-ui/color-mode
Created by: monacohq
Last modified: Tue, 05 Apr 2022 16:43:10 GMT
Version: 1.3.3
License: MIT
Downloads: 6
Repository: https://github.com/monacohq/hakuna-matata-ui

Install

npm install @hakuna-matata-ui/color-mode
yarn add @hakuna-matata-ui/color-mode

Color Mode

React component that adds support for light mode and dark mode using
localStorage and matchMedia.

Installation

 yarn add @hakuna-matata-ui/color-mode

# or

npm i @hakuna-matata-ui/color-mode

Import component

To enable this behavior within your apps, wrap your application in a
ColorModeProvider below the ThemeProvider

 import * as React from "react"
import { ColorModeProvider } from "@hakuna-matata-ui/color-mode"
import theme from "./theme"

function App({ children }) {
  return (
    <ThemeProvider theme={theme}>
      <ColorModeProvider>{children}</ColorModeProvider>
    </ThemeProvider>
  )
}

Then you can use the hook useColorMode within your application.

 function Example() {
  const { colorMode, toggleColorMode } = useColorMode()
  return (
    <header>
      <Button onClick={toggleColorMode}>
        Toggle {colorMode === "light" ? "Dark" : "Light"}
      </Button>
    </header>
  )
}

Dependencies

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code