Socket
Socket
Sign inDemoInstall

next-themes

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

next-themes


Version published
Weekly downloads
808K
decreased by-1.5%
Maintainers
1
Weekly downloads
 
Created

What is next-themes?

The next-themes package is a utility for managing themes in Next.js applications. It provides a simple and efficient way to implement dark mode, light mode, and custom themes with minimal configuration.

What are next-themes's main functionalities?

Theme Provider

The ThemeProvider component wraps your application and provides the context for theme management. The `attribute` prop specifies how the theme is applied, such as using a class or data attribute.

```jsx
import { ThemeProvider } from 'next-themes';

function MyApp({ Component, pageProps }) {
  return (
    <ThemeProvider attribute="class">
      <Component {...pageProps} />
    </ThemeProvider>
  );
}

export default MyApp;
```

Use Theme Hook

The `useTheme` hook allows you to access and manipulate the current theme. You can use it to create theme switchers or to apply theme-specific logic in your components.

```jsx
import { useTheme } from 'next-themes';

function ThemeSwitcher() {
  const { theme, setTheme } = useTheme();

  return (
    <div>
      <button onClick={() => setTheme('light')}>Light Mode</button>
      <button onClick={() => setTheme('dark')}>Dark Mode</button>
      <button onClick={() => setTheme('system')}>System Default</button>
    </div>
  );
}
```

Custom Themes

You can define custom themes and pass them to the ThemeProvider. This allows you to have more control over the appearance of your application and to create unique themes beyond just light and dark modes.

```jsx
import { ThemeProvider } from 'next-themes';

const customThemes = {
  light: {
    background: '#ffffff',
    color: '#000000'
  },
  dark: {
    background: '#000000',
    color: '#ffffff'
  }
};

function MyApp({ Component, pageProps }) {
  return (
    <ThemeProvider themes={customThemes} attribute="class">
      <Component {...pageProps} />
    </ThemeProvider>
  );
}

export default MyApp;
```

Other packages similar to next-themes

FAQs

Package last updated on 13 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc