Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename useImperativeMethods -> useImperativeHandle #1544

Merged
merged 3 commits into from
Jan 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion content/docs/hooks-faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ This might look strange at first, but an update during rendering is exactly what

### Can I make a ref to a function component?

While you shouldn't need this often, you may expose some imperative methods to a parent component with the [`useImperativeMethods`](/docs/hooks-reference.html#useimperativemethods) Hook.
While you shouldn't need this often, you may expose some imperative methods to a parent component with the [`useImperativeHandle`](/docs/hooks-reference.html#useimperativehandle) Hook.

### What does `const [thing, setThing] = useState()` mean?

Expand Down
10 changes: 5 additions & 5 deletions content/docs/hooks-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ If you're new to Hooks, you might want to check out [the overview](/docs/hooks-o
- [`useCallback`](#usecallback)
- [`useMemo`](#usememo)
- [`useRef`](#useref)
- [`useImperativeMethods`](#useimperativemethods)
- [`useImperativeHandle`](#useimperativehandle)
- [`useLayoutEffect`](#uselayouteffect)

## Basic Hooks
Expand Down Expand Up @@ -321,18 +321,18 @@ function TextInputWithFocusButton() {

Note that `useRef()` is useful for more than the `ref` attribute. It's [handy for keeping any mutable value around](/docs/hooks-faq.html#is-there-something-like-instance-variables) similar to how you'd use instance fields in classes.

### `useImperativeMethods`
### `useImperativeHandle`

```js
useImperativeMethods(ref, createInstance, [inputs])
useImperativeHandle(ref, createHandle, [inputs])
```

`useImperativeMethods` customizes the instance value that is exposed to parent components when using `ref`. As always, imperative code using refs should be avoided in most cases. `useImperativeMethods` should be used with `forwardRef`:
`useImperativeHandle` customizes the instance value that is exposed to parent components when using `ref`. As always, imperative code using refs should be avoided in most cases. `useImperativeHandle` should be used with `forwardRef`:

```js
function FancyInput(props, ref) {
const inputRef = useRef();
useImperativeMethods(ref, () => ({
useImperativeHandle(ref, () => ({
focus: () => {
threepointone marked this conversation as resolved.
Show resolved Hide resolved
inputRef.current.focus();
}
Expand Down