Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
hook-dark-mode
Advanced tools
React custom hook to handle dark mode based on user system appearence theme and localStorage
React custom hook to handle dark mode based on user system appearence theme and localStorage.
prefers-color-scheme
import { useDarkMode } from "hook-dark-mode"
The easiest way to use useDarkMode hook is to install it from npm or yarn.
npm install hook-dark-mode --save
Or
yarn add hook-dark-mode
Pull the hook into your component (usually the root one) and call the hook inside the functional component. Then based on the user preference you can add corresponding classes to the wrapper element.
import { useDarkMode } from "hook-dark-mode";
function App() {
const [prefersDarkMode, setDarkMode] = useDarkMode();
return (
<div className={"App " + (prefersDarkMode ? "dark" : "light")}>
<p>Current color mode: {prefersDarkMode ? "Dark" : "Light"}</p>
<button type="button" onClick={() => setDarkMode(!prefersDarkMode)}>
Set {prefersDarkMode ? "light" : "dark"} mode
</button>
</div>
);
}
In your css styles you would need the classes for dark and light mode according to your app design. For example,
.dark {
background-color: #282c34;
color: white;
}
.light {
background-color: white;
color: #282c34;
}
FAQs
React custom hook to handle dark mode based on user system appearence theme and localStorage
The npm package hook-dark-mode receives a total of 0 weekly downloads. As such, hook-dark-mode popularity was classified as not popular.
We found that hook-dark-mode demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.