Update "Refs and the DOM" documentation (#2657)

* Update "Refs and the DOM" documentation

As function components can now have state through hooks, remove the part that mentions converting a function component to a class component to be able to use state.

* Update refs-and-the-dom.md

Co-authored-by: Sophie Alpert <git@sophiebits.com>
This commit is contained in:
Evrim Persembe
2020-01-07 04:11:05 +04:00
committed by Sophie Alpert
parent 3413c785fa
commit 24ebabd01e

View File

@@ -140,7 +140,7 @@ class CustomTextInput extends React.Component {
#### Refs and Function Components {#refs-and-function-components}
**You may not use the `ref` attribute on function components** because they don't have instances:
By default, **you may not use the `ref` attribute on function components** because they don't have instances:
```javascript{1,8,13}
function MyFunctionComponent() {
@@ -161,7 +161,7 @@ class Parent extends React.Component {
}
```
You should convert the component to a class if you need a ref to it, just like you do when you need lifecycle methods or state.
If you want to allow people to take a `ref` to your function component, you can use [`forwardRef`](https://reactjs.org/docs/forwarding-refs.html) (possibly in conjunction with [`useImperativeHandle`](/docs/hooks-reference.html#useimperativehandle)), or you can convert the component to a class.
You can, however, **use the `ref` attribute inside a function component** as long as you refer to a DOM element or a class component: