Gathering detailed insights and metrics for react-lifecycles-compat
Gathering detailed insights and metrics for react-lifecycles-compat
Gathering detailed insights and metrics for react-lifecycles-compat
Gathering detailed insights and metrics for react-lifecycles-compat
@types/react-lifecycles-compat
TypeScript definitions for react-lifecycles-compat
react-lifecycles-compat-loose
Backwards compatibility polyfill for React class components
react-compat-lifecycles
inferno-lifecycles-compat
Backwards compatibility polyfill for React new class components in Inferno
Backwards compatibility polyfill for React class components
npm install react-lifecycles-compat
Typescript
Module System
Node Version
NPM Version
99.6
Supply Chain
85
Quality
77.8
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
1,831,357,175
Last Day
279,604
Last Week
6,290,805
Last Month
27,349,479
Last Year
306,206,910
MIT License
459 Stars
105 Commits
26 Forks
15 Watchers
29 Branches
16 Contributors
Updated on Mar 03, 2025
Minified
Minified + Gzipped
Latest Version
3.0.4
Package Id
react-lifecycles-compat@3.0.4
Size
5.86 kB
NPM Version
5.6.0
Node Version
8.11.1
Published on
May 11, 2018
Cumulative downloads
Total Downloads
Last Day
-12.9%
279,604
Compared to previous day
Last Week
-9.2%
6,290,805
Compared to previous week
Last Month
2.9%
27,349,479
Compared to previous month
Last Year
-16.2%
306,206,910
Compared to previous year
React version 17 will deprecate several of the class component API lifecycles: componentWillMount
, componentWillReceiveProps
, and componentWillUpdate
. (Read the Update on Async rendering blog post to learn more about why.) A couple of new lifecycles are also being added to better support async rendering mode.
Typically, this type of change would require third party libraries to release a new major version in order to adhere to semver. However, the react-lifecycles-compat
polyfill offers a way to use the new lifecycles with older versions of React as well (0.14.9+) so no breaking release is required. This enables shared libraries to support both older and newer versions of React simultaneously.
First, install the polyfill from NPM:
1# Yarn 2yarn add react-lifecycles-compat 3 4# NPM 5npm install react-lifecycles-compat --save
Next, update your component and replace any of the deprecated lifecycles with new ones introduced with React 16.3. (Refer to the React docs for examples of how to use the new lifecycles.)
Lastly, use the polyfill to make the new lifecycles work with older versions of React:
1import React from 'react'; 2import {polyfill} from 'react-lifecycles-compat'; 3 4class ExampleComponent extends React.Component { 5 static getDerivedStateFromProps(nextProps, prevState) { 6 // Normally this method would only work for React 16.3 and newer, 7 // But the polyfill will make it work for older versions also! 8 } 9 10 getSnapshotBeforeUpdate(prevProps, prevState) { 11 // Normally this method would only work for React 16.3 and newer, 12 // But the polyfill will make it work for older versions also! 13 } 14 15 // render() and other methods ... 16} 17 18// Polyfill your component so the new lifecycles will work with older versions of React: 19polyfill(ExampleComponent); 20 21export default ExampleComponent;
Currently, this polyfill supports static getDerivedStateFromProps
and getSnapshotBeforeUpdate
- both introduced in version 16.3.
Note that in order for the polyfill to work, none of the following lifecycles can be defined by your component: componentWillMount
, componentWillReceiveProps
, or componentWillUpdate
.
Note also that if your component contains getSnapshotBeforeUpdate
, componentDidUpdate
must be defined as well.
An error will be thrown if any of the above conditions are not met.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 2/14 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
64 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-06-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More