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.
react-controlled
Advanced tools
higher-order-component for react controlled components
npm install --save react-controlled
import React from 'react';
import controlled from 'react-controlled';
class MyComponent extends React.Component {
onClickSave = () => {
const nickname = this.props.fields('nickname').value;
const age = this.props.fields('age').value;
}
render() {
return <div>
<input type="text" {...this.props.fields('nickname')}/>
<input type="text" {...this.props.fields('age')}/>
<button onClick={this.onClickSave}>save</button>
</div>;
}
}
export default controlled(MyComponent)
It is recommanded to set default value at constructor.
import React from 'react';
import controlled from 'react-controlled';
class MyComponent extends React.Component {
constructor(props) {
super(props);
this.props.fields({
fieldName: 'nickname',
defaultValue: 'no name',
});
}
render() {
return <div>
<input type="text" {...this.props.fields('nickname')}/>
</div>;
}
}
export default controlled(MyComponent)
default getValue function: args => args[0].target.value
import React from 'react';
import controlled from 'react-controlled';
class MyComponent extends React.Component {
constructor(props) {
super(props);
this.props.fields({
fieldName: 'nickname',
getValue: args => args[0],
});
}
render() {
return <div>
<SomeComponent {...this.props.fields('nickname')}/>
</div>;
}
}
export default controlled(MyComponent)
import React from 'react';
import controlled from 'react-controlled';
class MyComponent extends React.Component {
onClick = () => {
const values = this.props.getFieldValues();
values.nickname = 'my name is ' + values.nickname;
values.age = 'my age is ' + values.age;
this.props.setFieldValues(values);
}
render() {
return <div>
<input type="text" {...this.props.fields('nickname')}/>
<input type="text" {...this.props.fields('age')}/>
<button onClick={this.onClick}>example</button>
</div>;
}
}
export default controlled(MyComponent)
FAQs
Useful higher-order-component for react controlled components
The npm package react-controlled receives a total of 1 weekly downloads. As such, react-controlled popularity was classified as not popular.
We found that react-controlled 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.