File tree 2 files changed +35
-1
lines changed
2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
10
10
For a steady stream of TILs from a variety of rocketeers, checkout
11
11
[ til.hashrocket.com] ( https://til.hashrocket.com/ ) .
12
12
13
- _ 660 TILs and counting..._
13
+ _ 661 TILs and counting..._
14
14
15
15
---
16
16
@@ -449,6 +449,7 @@ _660 TILs and counting..._
449
449
### React
450
450
451
451
- [ A Component Is Just A Bag Of Data] ( react/a-component-is-just-a-bag-of-data.md )
452
+ - [ Access The Latest Lifecycle Methods In An Old App] ( react/access-the-latest-lifecycle-methods-in-an-old-app.md )
452
453
- [ Accessing Env Vars In create-react-app] ( react/accessing-env-vars-in-create-react-app.md )
453
454
- [ Alter The Display Name Of A Component] ( react/alter-the-display-name-of-a-component.md )
454
455
- [ Building A React App In The Browser] ( react/building-a-react-app-in-the-browser.md )
Original file line number Diff line number Diff line change
1
+ # Access The Latest Lifecycle Methods In An Old App
2
+
3
+ With the release of React 16.3 we have access to some new lifecycle methods
4
+ and are in the first phase of what will eventually result in the deprecation
5
+ and removal of ` componentWillMount ` , ` componentWillReceiveProps ` , and
6
+ ` componentWillUpdate ` .
7
+
8
+ You may not be ready to move your project to React 16.3, but that doesn't
9
+ mean you can't start migrating your lifecycle methods now. We'll need a
10
+ polyfill --
11
+ [ react-lifecycles-compat] ( https://github.com/reactjs/react-lifecycles-compat ) .
12
+
13
+ ``` javascript
14
+ import React from ' react' ;
15
+ import { pollyfill } from ' react-lifecycles-compat' ;
16
+
17
+ class MyComponent extends React .Component {
18
+ static getDerivedStateFromProps (nextProps , prevState ) {
19
+ // ...
20
+ }
21
+
22
+ render () { ... }
23
+ }
24
+ polyfill (MyComponent)
25
+
26
+ export default MyComponent ;
27
+ ```
28
+
29
+ For any of our class components for which we'd like to start using the new
30
+ lifecycle methods, we just need to import the polyfill function and then
31
+ transform the class component with the polyfill before exporting it.
32
+
33
+ [ source] ( https://reactjs.org/blog/2018/03/27/update-on-async-rendering.html#open-source-project-maintainers )
You can’t perform that action at this time.
0 commit comments