This repository was archived by the owner on Feb 14, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +33
-6
lines changed
Expand file tree Collapse file tree 3 files changed +33
-6
lines changed Original file line number Diff line number Diff line change 1- import { ComponentClass } from 'react' ;
1+ import { ComponentClass , version } from 'react' ;
22import { Reducers , State } from '../default' ;
33import Callback from '../types/callback' ;
44import { ReactNComponentClass } from '../types/component-class' ;
@@ -58,8 +58,21 @@ export default function ReactN<
5858 }
5959 }
6060
61+ public UNSAFE_componentWillUpdate ( ...args : [ P , S , any ] ) : void {
62+ const [ rVerMaj , rVerMin ] = version . split ( '.' ) . map ( ( v ) : number => parseInt ( v ) ) ;
63+ if ( rVerMaj > 16 || ( rVerMaj === 16 && rVerMin >= 3 ) ) {
64+ ReactNComponentWillUpdate ( this ) ;
65+ }
66+ if ( super . UNSAFE_componentWillUpdate ) {
67+ super . UNSAFE_componentWillUpdate ( ...args ) ;
68+ }
69+ }
70+
6171 public componentWillUpdate ( ...args : [ P , S , any ] ) : void {
62- ReactNComponentWillUpdate ( this ) ;
72+ const [ rVerMaj , rVerMin ] = version . split ( '.' ) . map ( ( v ) : number => parseInt ( v ) ) ;
73+ if ( rVerMaj < 16 || ( rVerMaj === 16 && rVerMin < 3 ) ) {
74+ ReactNComponentWillUpdate ( this ) ;
75+ }
6376 if ( super . componentWillUpdate ) {
6477 super . componentWillUpdate ( ...args ) ;
6578 }
Original file line number Diff line number Diff line change 11import { Reducers , State } from '../../default' ;
22import { ReactNComponent , ReactNPureComponent } from '../../types/component' ;
3+ import React = require( 'react' ) ;
34import {
45 ReactNComponentWillUnmount ,
56 ReactNComponentWillUpdate ,
@@ -41,11 +42,17 @@ export default function bindLifecycleMethods<
4142 // !componentWillUpdateInstance(that) &&
4243 ! componentWillUpdatePrototype ( that )
4344 ) {
44-
45+ const [ rVerMaj , rVerMin ] = React . version . split ( '.' ) . map ( ( v ) : number => parseInt ( v ) ) ;
46+ if ( rVerMaj > 16 || ( rVerMaj === 16 && rVerMin >= 3 ) ) {
47+ that . UNSAFE_componentWillUpdate = ( ) : void => {
48+ ReactNComponentWillUpdate ( that ) ;
49+ } ;
50+ } else {
51+ that . componentWillUpdate = ( ) : void => {
52+ ReactNComponentWillUpdate ( that ) ;
53+ } ;
54+ }
4555 // Warning: If componentWillUpdate is defined in the constructor (or as an
4656 // arrow function), this will be overridden.
47- that . componentWillUpdate = ( ) : void => {
48- ReactNComponentWillUpdate ( that ) ;
49- } ;
5057 }
5158} ;
Original file line number Diff line number Diff line change @@ -46,6 +46,13 @@ export const componentWillUpdatePrototype = <
4646) : boolean => {
4747 const proto : ReactNComponent | ReactNPureComponent =
4848 Object . getPrototypeOf ( that ) ;
49+ if ( Object . prototype . hasOwnProperty . call ( proto , 'UNSAFE_componentWillUpdate' ) ) {
50+ that . UNSAFE_componentWillUpdate = ( ...args : [ P , S , any ] ) : void => {
51+ ReactNComponentWillUpdate ( that ) ;
52+ proto . UNSAFE_componentWillUpdate . bind ( that ) ( ...args ) ;
53+ } ;
54+ return true ;
55+ }
4956 if ( Object . prototype . hasOwnProperty . call ( proto , 'componentWillUpdate' ) ) {
5057 that . componentWillUpdate = ( ...args : [ P , S , any ] ) : void => {
5158 ReactNComponentWillUpdate ( that ) ;
You can’t perform that action at this time.
0 commit comments