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
Backwards compatibility polyfill for React class components
npm install react-lifecycles-compat
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
459 Stars
105 Commits
26 Forks
16 Watching
29 Branches
16 Contributors
Updated on 12 Aug 2024
Minified
Minified + Gzipped
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-1.8%
1,209,338
Compared to previous day
Last week
4.9%
6,344,358
Compared to previous week
Last month
9.2%
26,263,813
Compared to previous month
Last year
-14.3%
323,519,370
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
62 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
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