Skip to content

Commit 3780980

Browse files
committed
translated 87 lines in useImperativeHandle
1 parent 5b14fa6 commit 3780980

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/content/reference/react/useImperativeHandle.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: useImperativeHandle
44

55
<Intro>
66

7-
`useImperativeHandle` це хук, який дозволяє кастомізувати обєкт, який повертається через [реф.](/learn/manipulating-the-dom-with-refs)
7+
`useImperativeHandle` це хук, який дозволяє кастомізувати об'єкт, який повертається через [реф.](/learn/manipulating-the-dom-with-refs)
88

99
```js
1010
useImperativeHandle(ref, createHandle, dependencies?)
@@ -16,7 +16,7 @@ useImperativeHandle(ref, createHandle, dependencies?)
1616
1717
---
1818
19-
## Reference {/*reference*/}
19+
## Опис {/*reference*/}
2020
2121
### `useImperativeHandle(ref, createHandle, dependencies?)` {/*useimperativehandle*/}
2222
@@ -40,51 +40,51 @@ function MyInput({ ref }) {
4040
4141
* `ref`: `Реф`, який ви отримали як проп у компоненті `MyInput`.
4242
43-
* `createHandle`: A function that takes no arguments and returns the ref handle you want to expose. That ref handle can have any type. Usually, you will return an object with the methods you want to expose.
43+
* `createHandle`: Функція, яка не приймає аргументів і повертає об'єкт посилання, який ви хочете надати. Цей об’єкт може бути будь-якого типу. Зазвичай, ви повертатимете об'єкт з методами, які ви захочете використовувати.
4444
45-
* **optional** `dependencies`: The list of all reactive values referenced inside of the `createHandle` code. Reactive values include props, state, and all the variables and functions declared directly inside your component body. If your linter is [configured for React](/learn/editor-setup#linting), it will verify that every reactive value is correctly specified as a dependency. The list of dependencies must have a constant number of items and be written inline like `[dep1, dep2, dep3]`. React will compare each dependency with its previous value using the [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) comparison. If a re-render resulted in a change to some dependency, or if you omitted this argument, your `createHandle` function will re-execute, and the newly created handle will be assigned to the ref.
45+
* **Опціональний параметр** `dependencies`: Список усіх реактивних значень, на які посилається код `createHandle`. Реактивні значення включають в себе пропси, стан та всі змінні та функції, оголошені безпосередньо в тілі компонента. Якщо ваш лінтер [налаштований для Реакту](/learn/editor-setup#linting), він перевірить, чи кожне реактивне значення вказане як залежність. Список залежностей повинен містити стале число елементів, записаних в рядок як `[залежність1, залежність2, залежність3]`. Реакт порівняє кожну залежність із своїм попереднім значенням використовуючи порівняння [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is). Якщо повторний рендер призвів до зміни однієї із залежностей або якщо ви пропустили даний аргумент, ваша `createHandle` функція буде виконана повторно і новостворений об'єкт посилання буде призначений до рефу.
4646
4747
<Note>
4848
49-
Starting with React 19, [`ref` is available as a prop.](/blog/2024/12/05/react-19#ref-as-a-prop) In React 18 and earlier, it was necessary to get the `ref` from [`forwardRef`.](/reference/react/forwardRef)
49+
Починаючи з React 19 [`реф` доступний як проп.](/blog/2024/12/05/react-19#ref-as-a-prop) У React 18 і старіших версіях необхідно було отримувати `реф` з [`forwardRef`.](/reference/react/forwardRef)
5050
5151
</Note>
5252
53-
#### Returns {/*returns*/}
53+
#### Результат {/*returns*/}
5454
55-
`useImperativeHandle` returns `undefined`.
55+
`useImperativeHandle` повертає `undefined`.
5656
5757
---
5858
59-
## Usage {/*usage*/}
59+
## Використання {/*usage*/}
6060
61-
### Exposing a custom ref handle to the parent component {/*exposing-a-custom-ref-handle-to-the-parent-component*/}
61+
### Надання кастомного об'єкта посилання батьківському компоненту {/*exposing-a-custom-ref-handle-to-the-parent-component*/}
6262
63-
To expose a DOM node to the parent element, pass in the `ref` prop to the node.
63+
Щоб надати DOM-вузол батьківському елементу, передайте проп ref до цього вузла.
6464
6565
```js {2}
6666
function MyInput({ ref }) {
6767
return <input ref={ref} />;
6868
};
6969
```
7070
71-
With the code above, [a ref to `MyInput` will receive the `<input>` DOM node.](/learn/manipulating-the-dom-with-refs) However, you can expose a custom value instead. To customize the exposed handle, call `useImperativeHandle` at the top level of your component:
71+
У коді вище [посилання до `MyInput` отримає DOM вузол `<input>`.](/learn/manipulating-the-dom-with-refs) Однак, замість цього ви можете передати кастомне значення. Щоб кастомізувати наданий об'єкт посилання, викличте `useImperativeHandle` на верхньому рівні вашого компонента:
7272
7373
```js {4-8}
7474
import { useImperativeHandle } from 'react';
7575

7676
function MyInput({ ref }) {
7777
useImperativeHandle(ref, () => {
7878
return {
79-
// ... your methods ...
79+
// ... ваші методи ...
8080
};
8181
}, []);
8282

8383
return <input />;
8484
};
8585
```
8686
87-
Note that in the code above, the `ref` is no longer passed to the `<input>`.
87+
Зверніть увагу, що в наданому вище коді `реф` більше не передається до `<input>`.
8888
8989
For example, suppose you don't want to expose the entire `<input>` DOM node, but you want to expose two of its methods: `focus` and `scrollIntoView`. To do this, keep the real browser DOM in a separate ref. Then use `useImperativeHandle` to expose a handle with only the methods that you want the parent component to call:
9090

0 commit comments

Comments
 (0)