1.2.1 • Published 3 years ago

@lovenmonsters/theme-changer v1.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

React Theme Changer

This is a custom react hook which lets you change your theme based on darkMode: "class" in Tailwind CSS config. It supports both React and Next.js.

Usage

Install the package using your favourite package manager.

Using npm:

npm i @lovenmonsters/theme-changer

Using yarn:

yarn add @lovenmonsters/theme-changer

Import useTheme function from @lovenmonsters/theme-changer in your component and follow the example below.

import { useTheme } from '@lovenmonsters/theme-changer';

Don't forget to change darkMode to class in tailwind.config.js.

Example Code

import Head from 'next/head';
import { useTheme } from '@lovenmonsters/theme-changer';

export default function Home() {
  const [colorTheme, setColorTheme] = useTheme();

  return (
    <>
      <Head>
        <title>Theme Changer</title>
        <meta name="description" content="React Theme Changer" />
        <link rel="icon" href="/favicon.ico" />
      </Head>

      <div className="w-full h-screen flex justify-center items-center">
        {colorTheme === 'light' ? (
          <button className="text-yellow-500" onClick={() => setColorTheme('light')}>
            Change to Light
          </button>
        ) : (
          <button className="text-indigo-600" onClick={() => setColorTheme('dark')}>
            Change to Dark
          </button>
        )}
      </div>
    </>
  );
}
1.2.1

3 years ago

1.2.0

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago