
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
compose-react
Advanced tools
A higher order function for wrapping react components many times.
npm i -S compose-react
If your project uses HOC's (Higher-Order Components) like react-redux/react-router to wrap react components
Using more than 1 HOC results in deeply nested or verbose code
// deeply nested single line statement
export default withStyles(styles)(withRouter(connect(mapDispatchToProps, mapDispatchToProps)(MyReactButton)));
// verbose multiple assignments
MyReactButton = withStyles(styles)(MyReactButton);
MyReactButton = withRouter(MyReactButton);
MyReactButton = connect(mapDispatchToProps, mapDispatchToProps)(MyReactButton);
export default MyReactButton;
compose-react will allow HOC's to be composed
export default compose(
withStyles(styles),
withRouter,
connect(mapStateToProps, mapDispatchToProps)
)(MyReactButton);
How to use compose-react's compose method
import React from 'react';
import { withStyles } from '@material-ui/core/styles';
import { withRouter } from 'react-router-dom';
import { connect } from 'react-redux';
import { compose } from 'compose-react';
const styles = theme => ({
container: {
backgroundColor: theme.palette.primary.main,
padding: theme.spacing.unit
}
});
const MyReactButton = ({ isFetching, handleClick, classes }) => (
<div className={classes.container}>
<input
onClick={handleClick}
disabled={isFetching}
type="button"
value="Click me!"
/>
</div>
);
const mapStateToProps = state => ({
isFetching: state.isFetching
});
const mapDispatchToProps = dispatch => ({
handleClick: () => dispatch({ type: 'CLICKED' })
});
export default compose(
withStyles(styles),
withRouter,
connect(
mapStateToProps,
mapDispatchToProps
)
)(MyReactButton);
FAQs
Compose react components
The npm package compose-react receives a total of 2 weekly downloads. As such, compose-react popularity was classified as not popular.
We found that compose-react 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.