
Security News
MCP Steering Committee Launches Official MCP Registry in Preview
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.
react-on-off-state
Advanced tools
React component to manage on/off states
npm install react-on-off-state
# or
yarn add react-on-off-state
import React from "react";
import ReactDOM from "react-dom";
import OnOffState from "react-on-off-state";
ReactDOM.render(
<OnOffState>
{({ on, toggle }) => (
<>
<h1>{on ? "Red" : "Blue"}</h1>
<button onClick={toggle}>Change pill</button>
</>
)}
</OnOffState>,
document.getElementById("root")
);
boolean
| optional, defaults tofalse
The initial on
state.
boolean
| optional, control prop
By default, react-on-off-state
manages its own state. You can use the on
prop if you want to control the state by yourself.
(on: boolean) => any
| optional
Called whenever the state changes.
on: boolean
– The new state
(options: RenderOptions) => React.Node
| required
The children
prop is treated as a render prop. This is where you render whatever you want based on the state of react-on-off-state
.
options: RenderOptions
– An object with the following properties:Property | Description |
---|---|
on: boolean | true if the state is on, false otherwise |
off: boolean | convenience prop if you need !on |
setOn: () => void | Sets the state to on |
setOff: () => void | Sets the state to off |
toggle: () => void | Toggles the state (i.e. when it's on, will set to off and vice versa) |
The design and API mostly comes from react-toggled
. react-on-off-state
is a more generic version of it that only manages state and nothing more. You can think of it as a pre-build state machine. It's useful whenever you want to render not just a toggle component but anything that has two states.
MIT
FAQs
React component to manage on/off states
We found that react-on-off-state 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
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.
Product
Socket’s new Pull Request Stories give security teams clear visibility into dependency risks and outcomes across scanned pull requests.
Research
/Security News
npm author Qix’s account was compromised, with malicious versions of popular packages like chalk-template, color-convert, and strip-ansi published.