Skip to content

Commit ec7ce99

Browse files
committed
Added a note about polyfilling considerations
1 parent 1614da0 commit ec7ce99

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

text/0000-new-commit-phase-lifecycles.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ class Example extends React.Component<Props, State, Snapshot> {}
8686
class Example extends React.Component<Props, State = void, Snapshot> {}
8787
```
8888

89+
### Polyfill support
90+
91+
It might be possible for [react-lifecycles-compat](https://github.com/reactjs/react-lifecycles-compat) to polyfill this new method for older, synchronous versions of React using the `componentWillUpdate` lifecycle. To support this, we should follow the precedent set by `getDerivedStateFromProps` and not call the call _unsafe_ legacy lifecycles `componentWillMount`, `componentWillReceiveProps`, or `componentWillUpdate` for any component that defines the new `getSnapshotBeforeUpdate` method. (This would avoid executing code twice for newer versions of React.)
92+
93+
A DEV warning could be added for components that define both `getSnapshotBeforeUpdate` and any of the unsafe legacy lifecycles.
94+
8995
# Drawbacks
9096

9197
Each new lifecycle adds complexity and makes the component API harder for beginners to understand. Although this lifecycle _is important_, it will probably _not be used often_, and so I think the impact is minimal.

0 commit comments

Comments
 (0)