[Learn more about the forwardRef API here.](/docs/forwarding-refs.html)
## Component Lifecycle Changes
## Component Lifecycle Changes
React's class component API has been around for years with little change. However, as we add support for more advanced features (such as [error boundaries](/docs/react-component.html#componentdidcatch) and the upcoming [async rendering mode](/blog/2018/03/01/sneak-peek-beyond-react-16.html)) we stretch this model in ways that it was not originally intended.
React's class component API has been around for years with little change. However, as we add support for more advanced features (such as [error boundaries](/docs/react-component.html#componentdidcatch) and the upcoming [async rendering mode](/blog/2018/03/01/sneak-peek-beyond-react-16.html)) we stretch this model in ways that it was not originally intended.
@ -20,3 +20,18 @@ This means that refs intended for our `FancyButton` component will actually be a
Fortunately, we can explicitly forward refs to the inner `FancyButton` component using the `React.forwardRef` API. `React.forwardRef` accepts a render function that receives `props` and `ref` parameters and returns a React node. For example:
Fortunately, we can explicitly forward refs to the inner `FancyButton` component using the `React.forwardRef` API. `React.forwardRef` accepts a render function that receives `props` and `ref` parameters and returns a React node. For example:
`embed:forwarding-refs/log-props-after.js`
`embed:forwarding-refs/log-props-after.js`
## Displaying a custom name in DevTools
`React.forwardRef` accepts a render function. React DevTools uses this function to determine what to display for the ref forwarding component.
For example, the following component will appear as "*ForwardRef*" in the DevTools:
`embed:forwarding-refs/wrapped-component.js`
If you name the render function, DevTools will also include its name (e.g. "*ForwardRef(myFunction)*"):