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-redux-simple
Advanced tools
An alternative way to connect React components to a Redux store.
import React from "react";
import { connect } from "react-redux-simple";
import * as selectors from "./selectors";
import * as actions from "./actions";
class Counter extends React.Component {
static selectors = {
count: selectors.getCount
}
static actions = {
inc: actions.increment,
dec: actions.decrement
}
render() {
let { count, inc, dec } = this.props;
return (
<div>
<button onClick={dec}>-</button>
<span>{count}</span>
<button onClick={inc}>+</button>
</div>
);
}
}
export default connect(Counter)
Or with a functional component:
const Counter = ({ count, inc, dec }) => (
<div>
<button onClick={dec}>-</button>
<span>{count}</span>
<button onClick={inc}></button>
</div>
);
Counter.selectors = {
count: selectors.getCount
};
Counter.actions = {
inc: actions.increment,
dec: actions.decrement
};
export default connect(Counter)
You'll need to install both this package and react-redux
:
npm install react-redux react-redux-simple
An optional mapping of prop names to selectors (a function which takes the state and returns a value).
static selectors = {
count: state => state.count
}
If your selectors depend on the components own props, then selectors
can be a function instead.
static selectors = props => ({
count: state => state.count * props.multiplier
})
A common pattern is to name your selectors and group them in their own file (or colocate them with reducers).
import * as ToolSelectors from "./selectors/tool";
import * as ViewSelectors from "./selectors/view";
class Artboard extends Component {
static selectors = {
tool: ToolSelectors.getCurrentTool,
width: ViewSelectors.getVisibleWidth,
height: ViewSelectors.getVisibleHeight
};
}
An optional mapping of prop names to action creators (a function which returns an action).
static actions = {
increment: amount => ({ type: "INCREMENT", amount })
}
Another common pattern is to name and group actions in related files, then import them into the components that need them.
import * as ToolActions from "./actions/tool";
import * as ViewActions from "./actions/view";
class Artboard extends Component {
static actions = {
setTool: ToolActions.setCurrentTool,
setWidth: ViewActions.setVisibleWidth,
setHeight: ViewActions.setVisibleHeight
};
}
<Provide />
?You still need to make sure that your components have access to the store. The easiest way to do this is to have a <Provide />
component at the root
of your component tree.
import { Provide } from "react-redux"; // or from "react-redux-simple";
ReactDOM.render(
<Provide store={myStore}>
<App />
</Provide>
);
mergeProps
and options
?This is designed to be a stupidly simple wrapper, if you need more control you can just use the React-Redux version of connect
for a component with specific needs.
FAQs
A selector friendly shortcut for React-Redux
The npm package react-redux-simple receives a total of 0 weekly downloads. As such, react-redux-simple popularity was classified as not popular.
We found that react-redux-simple 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.