theme-change-react
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

This is a simple package to switch between light and dark themes, and it can also switch the theme depending on the theme of the device.

npm run theme-change-react

CSS

  html[data-theme=light] body {
    background-color: white;
  }

  html[data-theme=dark] body {
    background-color: black;
  }

React

import {ChangeThemeProvider, useChangeTheme} from 'theme-change-react'

const root = ReactDOM.createRoot(document.getElementById('root'))

root.render(
  <React.StrictMode>
    <ChangeThemeProvider insertAt='body'>
      <App />
    </ChangeThemeProvider>
  </React.StrictMode>
)

function SwitcherTheme() {
  const {isDarkMode, changeThemeMode} = useChangeTheme()

  return (
    <div>
      Enable dark theme:
      <input
        type='checkbox'
        value={isDarkMode}
        onChange={changeThemeMode}
      />
    </div>
  )
}

Dependencies (0)

    Dev Dependencies (9)

    Package Sidebar

    Install

    npm i theme-change-react

    Weekly Downloads

    2

    Version

    1.0.5

    License

    ISC

    Unpacked Size

    5.06 kB

    Total Files

    7

    Last publish

    Collaborators

    • bergamolt