
Security News
/Research
Popular node-ipc npm Package Infected with Credential Stealer
Socket detected malicious node-ipc versions with obfuscated stealer/backdoor behavior in a developing npm supply chain attack.
react-singleton-component
Advanced tools
Easiest way to control the state from outside of the React world.
npm i react-singleton-component
import { createSingletonComponent } from "react-singleton-component";
const SelfIntroduction = createSingletonComponent(
{ name: "John Smith", age: 35 },
props => <p style={{color: props.color}}>{props.name} ({props.age})</p>
);
ReactDOM.render(<SelfIntroduction color="blue" />, document.getElementById("container"));
SelfIntroduction.setState({ age: SelfIntroduction.state.age + 1 });
createSingletonComponent returns a React.Component constructor with static method setState and static property state. The first argument is used as the default state of the returned component, and passed as the props of the component specified in the second argument.
createSingletonComponent has two generics parameters of props and state. They will be combined to one object and passed as props.
type Props = { color: string };
type State = { name: string, age: number };
const SelfIntroduction = createSingletonComponent<Props, State>(
{ name: "John Smith", age: 35 },
props => <p style={{color: props.color}}>{props.name} ({props.age})</p>
);
ReactDOM.render(<SelfIntroduction color="blue" />, document.getElementById("container"));
SelfIntroduction.setState({ age: SelfIntroduction.state.age + 1 });
If you do not need props, TypeScript language server will automatically infer the type of state!
FAQs
Easiest way to control the state from outside of the React world.
The npm package react-singleton-component receives a total of 7 weekly downloads. As such, react-singleton-component popularity was classified as not popular.
We found that react-singleton-component 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
/Research
Socket detected malicious node-ipc versions with obfuscated stealer/backdoor behavior in a developing npm supply chain attack.

Security News
TeamPCP and BreachForums are promoting a Shai-Hulud supply chain attack contest with a $1,000 prize for the biggest package compromise.

Security News
Packagist urges PHP projects to update Composer after a GitHub token format change exposed some GitHub Actions tokens in CI logs.