
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
switch-mode
Advanced tools
A react custom component that allows developers to add a toggle theme functionality in their projects seamlessly with its value persisted over the localStorage.
This is a custom react component that allows developers to add a toggle theme functionality in their projects seamlessly with its value persisted over the localStorage. Here, with the aid of react context API, values of props are able to be passed down to the specific components that need the required data.
Run npm install switch-mode
||
yarn add switch-mode
- import {ThemeProvider} from "switch-mode" and wrap your root component that will be rendered
- In the consuming component, import {useTheme, ToggleSwitch} from "switch-mode"
- Just before the return keyword of your consuming component, destructure `{theme}` from useTheme()
- And finally in your parent `div` tag, customize your backgroundColor and color
- Use the syntax: div style = {{backgroundColor: theme === "light" ? "black" : "white", color: theme === "light" ? "white" : "black"}}
import React from "react";
import { useTheme, ToggleSwitch } from "switch-mode";
function App() {
const { theme } = useTheme();
return ();<ToggleSwitch /> <h2> Some text here** </h2> <Main> `switch-mode` is a custom component used in react for enhancing user interfaces with dark/light themes </Main> <small>Created by Israel Abazie on February 22, 2023</small>
}
export default App;
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import {ThemeProvider} from "switch-mode";
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
</React.StrictMode>
);
// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
FAQs
A react custom component that allows developers to add a toggle theme functionality in their projects seamlessly with its value persisted over the localStorage.
The npm package switch-mode receives a total of 0 weekly downloads. As such, switch-mode popularity was classified as not popular.
We found that switch-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.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.