You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+18-45Lines changed: 18 additions & 45 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,9 +2,9 @@
2
2
3
3
## What is this project?
4
4
5
-
React version 17 will deprecate several of the class component API lifecycles: `componentWillMount`, `componentWillReceiveProps`, and `componentWillUpdate`. (See [React RFC 6](https://github.com/reactjs/rfcs/pull/6) for more information about this decision.)
5
+
React version 17 will deprecate several of the class component API lifecycles: `componentWillMount`, `componentWillReceiveProps`, and `componentWillUpdate`. (Read the [Update on Async rendering blog post](https://deploy-preview-596--reactjs.netlify.com/blog/2018/03/15/update-on-async-rendering.html) to learn more about why.) A couple of new lifecycles are also being added to better support [async rendering mode](https://reactjs.org/blog/2018/03/01/sneak-peek-beyond-react-16.html).
6
6
7
-
This would typically require any third party libraries dependent on those lifecycles to release a new major version in order to adhere to semver. However, the `react-lifecycles-compat` polyfill offers a way to remain compatible with older versions of React (0.14.9+). 🎉😎
7
+
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.
if (prevState.someMirroredValue!==nextProps.someValue) {
45
-
return {
46
-
derivedData:computeDerivedState(nextProps),
47
-
someMirroredValue:nextProps.someValue
48
-
};
49
-
}
50
-
51
-
// Return null to indicate no change to state.
52
-
returnnull;
53
-
}
54
-
}
55
-
```
20
+
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](https://deploy-preview-596--reactjs.netlify.com/blog/2018/03/15/update-on-async-rendering.html).)
56
21
57
-
Lastly, use the polyfill to make your component backwards compatible with older versions of React:
22
+
Lastly, use the polyfill to make the new lifecycles work with older versions of React:
// Polyfill your component to work with older versions of React:
31
+
// Polyfill your component so the new lifecycles will work with older versions of React:
71
32
polyfill(ExampleComponent);
72
33
73
34
exportdefaultExampleComponent;
74
-
```
35
+
```
36
+
37
+
## Which lifecycles are supported?
38
+
39
+
Currently, this polyfill supports [static `getDerivedStateFromProps`](https://deploy-preview-587--reactjs.netlify.com/docs/react-component.html#static-getderivedstatefromprops) and [`getSnapshotBeforeUpdate`](https://deploy-preview-587--reactjs.netlify.com/docs/react-component.html#getsnapshotbeforeupdate)- both introduced in version 16.3.
40
+
41
+
## Validation
42
+
43
+
Note that in order for the polyfill to work, none of the following lifecycles can be defined by your component: `componentWillMount`, `componentWillReceiveProps`, or `componentWillUpdate`.
44
+
45
+
Note also that if your component contains `getSnapshotBeforeUpdate`, `componentDidUpdate` must be defined as well.
46
+
47
+
An error will be thrown if any of the above conditions are not met.
0 commit comments