
Research
/Security News
Malicious npm Packages Target WhatsApp Developers with Remote Kill Switch
Two npm packages masquerading as WhatsApp developer libraries include a kill switch that deletes all files if the phone number isn’t whitelisted.
react-pure-lifecycle
Advanced tools
Add lifecycle methods to your functional components with purity
$ npm i react-pure-lifecycle --save
import React from 'react';
import lifecycle from 'react-pure-lifecycle';
// create your lifecycle methods
const componentDidMount = (props) => {
console.log('I mounted! Here are my props: ', props);
};
// make them properties on a standard object
const methods = {
componentDidMount
};
const FunctionalComponent = ({children}) => {
return (
<div>
{children}
</div>
);
};
// decorate the component
export default lifecycle(methods)(FunctionalComponent);
The complete list of lifecycle methods are supported, minus constructor
(if you want to fire something as early as possible, use componentWillMount
). The first parameter passed to each lifecycle method is the component's current props
, and then all standard parameters for that given lifecycle method follow. For a detailed explanation of each of the methods and the parameters they expect, check the React documentation.
In addition to functional components, you can use this on a standard React class:
import React, {
Component
} from 'react';
import lifecycle from 'react-pure-lifecycle';
const componentDidUpdate = (props, previousProps) => {
console.log('I updated! Here are my current and previous props: ', props, previousProps);
};
const methods = {
componentDidUpdate
};
@lifecycle(methods)
class ComponentClass extends Component {
render() {
const {
children
} = this.props;
return (
<div>
{children}
</div>
);
}
}
Not a whole lot of gain here other than the fact that you now have a pure function that you can test independently (no need to create an instance).
Finally, each lifecycle method is also provided as their own decorator, if you just want to bind a single method (receives the method itself instead of an object of methods):
import React from 'react';
import {
shouldComponentUpdate
} from 'react-pure-lifecycle';
const onlyUpdateIfChanged = (props, nextProps) => {
return props.children !== nextProps.children;
};
const FunctionalComponent = ({children}) => {
return (
<div>
{children}
</div>
);
};
// decorate the component
export default shouldComponentUpdate(onlyUpdateIfChanged)(FunctionalComponent);
Standard stuff, clone the repo and npm install
dependencies. The npm scripts available:
build
=> run webpack to build unminified JS with NODE_ENV
set to development
and source mapbuild:minifed
=> run webpack to build minified JS with NODE_ENV
set to production
clean
=> run rimraf
on both lib
and dist
lint
=> run ESLint against all files in the src
folderprepublish
=> runs prepubish:compile
prepublish:compile
=> run clean
, lint
, test
, transpile
, build
, and build-minified
start
=> run webpack dev server to run example app (playground!)test
=> run AVA test functions with NODE_ENV=test
test:coverage
=> run test
with nyc to get output of code coveragetest:watch
=> run test
, but with persistent watchertranspile
=> run babel against all files in src
to create files in lib
1.0.1-1.0.2
FAQs
Add pure function lifecycle methods to any React component
The npm package react-pure-lifecycle receives a total of 537 weekly downloads. As such, react-pure-lifecycle popularity was classified as not popular.
We found that react-pure-lifecycle 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
Two npm packages masquerading as WhatsApp developer libraries include a kill switch that deletes all files if the phone number isn’t whitelisted.
Research
/Security News
Socket uncovered 11 malicious Go packages using obfuscated loaders to fetch and execute second-stage payloads via C2 domains.
Security News
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.