Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
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
The npm package react-on-off-state receives a total of 1 weekly downloads. As such, react-on-off-state popularity was classified as not popular.
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
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.