Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
nextjs-themes
Advanced tools
Unleash the Power of React Server Components! Use multiple themes on your site with confidence, without losing any advantages of React Server Components.
Note: react18-themes will now be maintained as nextjs-themes
, as server-specific APIs are no longer needed.
🤟 👉 Unleash the Power of React Server Components
import from nextjs-themes/client/component
)Exampand following to see more features.
This project was inspired by next-themes. Unlike next-themes, nextjs-themes
doesn't require wrapping everything in a provider, allowing you to take full advantage of React 18 Server Components. Additionally, it offers more features and control over your app's theming.
import from nextjs-themes/client/component
)appDir
useTheme
hookCheck out the live example.
See Getting Started
Want Lite Version? In case you are using
r18gs
in your project, you may use lite version which requiresr18gs
as a peerDependency.
In tailwind.config.js
, set the dark mode property to class:
// tailwind.config.js
module.exports = {
darkMode: "class",
};
⚡🎉Ready to use dark mode in Tailwind!
Caution: Your class must be
"dark"
, which is the default value used in this library. Tailwind requires the class name"dark"
for dark-theme.
Use dark-mode specific classes:
<h1 className="text-black dark:text-white">
Refer to the migration guide.
Want a hands-on course for getting started with Turborepo? Check out React and Next.js with TypeScript
Do I need to use CSS variables with this library?
No. You can hard code values for every class:
.my-class {
color: #555;
}
[data-theme="dark"] .my-class {
color: white;
}
Why is resolvedTheme
and resolvedColorScheme
necessary?
To reflect the System theme preference and forced theme/colorScheme pages in your UI. For instance, buttons or dropdowns indicating the current colorScheme should say "system" when the System colorScheme preference is active.
resolvedTheme
is useful for modifying behavior or styles at runtime:
const { resolvedTheme, resolvedColorScheme } = useTheme();
const background = getBackground(resolvedTheme);
<div style={{ color: resolvedColorScheme === 'dark' ? white : black, background }}>
Without resolvedTheme
, you would only know the theme is "system", not what it resolved to.
This library is licensed under the MPL-2.0 open-source license.
Please consider enrolling in our courses or sponsoring our work.
with 💖 by Mayank Kumar Chaudhari
FAQs
Unleash the Power of React Server Components! Use multiple themes on your site with confidence, without losing any advantages of React Server Components.
The npm package nextjs-themes receives a total of 1,435 weekly downloads. As such, nextjs-themes popularity was classified as popular.
We found that nextjs-themes demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.