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: src/content/reference/react/Component.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1013,6 +1013,8 @@ Deriving state leads to verbose code and makes your components difficult to thin
1013
1013
1014
1014
- This method doesn't have access to the component instance. If you'd like, you can reuse some code between `static getDerivedStateFromProps` and the other class methods by extracting pure functions of the component props and state outside the class definition.
1015
1015
1016
+
- If your legacy component is defined with [`createReactClass`](https://legacy.reactjs.org/docs/react-without-es6.html), define `getDerivedStateFromProps` in the `statics` object.
1017
+
1016
1018
<Note>
1017
1019
1018
1020
Implementing `static getDerivedStateFromProps` in a class component is equivalent to [calling the `set` function from `useState` during rendering](/reference/react/useState#storing-information-from-previous-renders) in a function component.
0 commit comments