mirror of
https://github.com/reactjs/react.dev.git
synced 2026-02-23 20:23:08 +00:00
Explicitly note that ref callbacks are called before componentDidMount.
This commit is contained in:
committed by
Ken Powers
parent
ff8ef817e3
commit
efe928284a
@@ -66,7 +66,7 @@ class CustomTextInput extends React.Component {
|
||||
}
|
||||
```
|
||||
|
||||
React will call the `ref` callback with the DOM element when the component mounts, and call it with `null` when it unmounts.
|
||||
React will call the `ref` callback with the DOM element when the component mounts, and call it with `null` when it unmounts. `ref` callbacks will be called before `componentDidMount`.
|
||||
|
||||
Using the `ref` callback just to set a property on the class is a common pattern for accessing DOM elements. The preferred way is to set the property in the `ref` callback like in the above example. There is even a shorter way to write it: `ref={input => this.textInput = input}`.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user