Skip to content

Commit

Permalink
Update "Refs and the DOM" documentation (reactjs#2657)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
evrimfeyyaz and sophiebits committed Jan 7, 2020
1 parent 3413c78 commit 24ebabd
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions content/docs/refs-and-the-dom.md
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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:

Expand Down

0 comments on commit 24ebabd

Please sign in to comment.