All Projects → reactjs → React Lifecycles Compat

reactjs / React Lifecycles Compat

Licence: mit
Backwards compatibility polyfill for React class components

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Lifecycles Compat

Resize Observer
Polyfills the ResizeObserver API.
Stars: ✭ 540 (+18.16%)
Mutual labels:  api, polyfill
Share Api Polyfill
A polyfill for the sharing that can be used in desktop too, so your users can shere in their twitter, facebook, messenger, linkedin, sms, e-mail, print, telegram or whatsapp.
Stars: ✭ 210 (-54.05%)
Mutual labels:  api, polyfill
Clipboard Polyfill
📋 Simple copying on the web, with maximum browser compatibility.
Stars: ✭ 748 (+63.68%)
Mutual labels:  api, polyfill
Eslint Plugin Compat
Lint the browser compatibility of your code
Stars: ✭ 2,743 (+500.22%)
Mutual labels:  api, polyfill
Revapi
Revapi is an API analysis and change tracking tool written in Java. Its focus is mainly on Java language itself but it has been specifically designed to not be limited to just Java. API is much more than just java classes - also various configuration files, schemas, etc. can contribute to it and users can become reliant on them.
Stars: ✭ 122 (-73.3%)
Mutual labels:  api, compatibility
PHPUnit-Polyfills
Set of polyfills for changed PHPUnit functionality to allow for creating PHPUnit cross-version compatible tests
Stars: ✭ 147 (-67.83%)
Mutual labels:  polyfill, compatibility
Flextype
Hybrid Content Management System with the freedom of a headless CMS and with the full functionality of a traditional CMS
Stars: ✭ 436 (-4.6%)
Mutual labels:  api
Goa
Design-based APIs and microservices in Go
Stars: ✭ 4,493 (+883.15%)
Mutual labels:  api
Jwt sessions
XSS/CSRF safe JWT auth designed for SPA
Stars: ✭ 431 (-5.69%)
Mutual labels:  api
Jwtrefreshtokenbundle
Implements a Refresh Token system over Json Web Tokens in Symfony
Stars: ✭ 425 (-7%)
Mutual labels:  api
Service Pattern Go
Simple clean Go REST API architecture with dependency injection and mocking example, following SOLID principles.
Stars: ✭ 449 (-1.75%)
Mutual labels:  api
New Website
🖥 cdnjs.com website
Stars: ✭ 449 (-1.75%)
Mutual labels:  api
Apiadmin
基于ThinkPHP V6.*开发的面向API的后台管理系统!
Stars: ✭ 448 (-1.97%)
Mutual labels:  api
Crudl
CRUDL is a backend agnostic REST and GraphQL based admin interface
Stars: ✭ 438 (-4.16%)
Mutual labels:  api
Normalizr
Normalizes nested JSON according to a schema
Stars: ✭ 20,721 (+4434.14%)
Mutual labels:  api
Laravel Api Response Builder
Builds nice, normalized and easy to consume Laravel REST API JSON responses.
Stars: ✭ 433 (-5.25%)
Mutual labels:  api
React Native Vision Camera
📸 The Camera library that sees the vision.
Stars: ✭ 443 (-3.06%)
Mutual labels:  api
Fetchr
Universal data access layer for web applications.
Stars: ✭ 431 (-5.69%)
Mutual labels:  api
Go Binance
A Go SDK for Binance API
Stars: ✭ 441 (-3.5%)
Mutual labels:  api
Django Rest Framework
Web APIs for Django. 🎸
Stars: ✭ 22,406 (+4802.84%)
Mutual labels:  api

react-lifecycles-compat

What is this project?

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.

How can I use the polyfill

First, install the polyfill from NPM:

# Yarn
yarn add react-lifecycles-compat

# NPM
npm 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:

import React from 'react';
import {polyfill} from 'react-lifecycles-compat';

class ExampleComponent extends React.Component {
  static getDerivedStateFromProps(nextProps, prevState) {
    // Normally this method would only work for React 16.3 and newer,
    // But the polyfill will make it work for older versions also!
  }

  getSnapshotBeforeUpdate(prevProps, prevState) {
    // Normally this method would only work for React 16.3 and newer,
    // But the polyfill will make it work for older versions also!
  }

  // render() and other methods ...
}

// Polyfill your component so the new lifecycles will work with older versions of React:
polyfill(ExampleComponent);

export default ExampleComponent;

Which lifecycles are supported?

Currently, this polyfill supports static getDerivedStateFromProps and getSnapshotBeforeUpdate- both introduced in version 16.3.

Validation

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].