Skip to content

Commit 1f04c7f

Browse files
committed
completed translating useImperativeHandle page
1 parent 3780980 commit 1f04c7f

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/content/reference/react/useImperativeHandle.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function MyInput({ ref }) {
8686
8787
Зверніть увагу, що в наданому вище коді `реф` більше не передається до `<input>`.
8888
89-
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:
89+
Наприклад, припустимо, ви не хочете використовувати весь вузол DOM `<input>`, а лише два його методи: `focus` і `scrollIntoView`. Щоб зробити це, зберігайте справжній браузерний DOM у окремому посиланні. Потім викличте `useImperativeHandle` щоб повернути об'єкт, який містить лише ті методи, які ви хочете, щоб батьківський компонент викликав:
9090
9191
```js {7-14}
9292
import { useRef, useImperativeHandle } from 'react';
@@ -109,7 +109,7 @@ function MyInput({ ref }) {
109109
};
110110
```
111111
112-
Now, if the parent component gets a ref to `MyInput`, it will be able to call the `focus` and `scrollIntoView` methods on it. However, it will not have full access to the underlying `<input>` DOM node.
112+
Тепер, якщо батьківський компонент передасть реф до `MyInput`, він буде здатний викликати методи `focus` і `scrollIntoView` в компоненті. Однак, він не буде мати повного доступу до DOM вузла `<input>`.
113113
114114
<Sandpack>
115115
@@ -122,7 +122,7 @@ export default function Form() {
122122

123123
function handleClick() {
124124
ref.current.focus();
125-
// This won't work because the DOM node isn't exposed:
125+
// Це не спрацює, бо вузол DOM не був представлений:
126126
// ref.current.style.opacity = 0.5;
127127
}
128128

@@ -170,9 +170,9 @@ input {
170170
171171
---
172172
173-
### Exposing your own imperative methods {/*exposing-your-own-imperative-methods*/}
173+
### Передавання власних імперативних методів {/*exposing-your-own-imperative-methods*/}
174174
175-
The methods you expose via an imperative handle don't have to match the DOM methods exactly. For example, this `Post` component exposes a `scrollAndFocusAddComment` method via an imperative handle. This lets the parent `Page` scroll the list of comments *and* focus the input field when you click the button:
175+
Методи, які ви передаєте через імперативний обробник не обов'язково мають точно відповідати DOM методам. Наприклад, даний компонент `Post` передає метод `scrollAndFocusAddComment` через імперативний обробник. Це дозволяє батьківському компоненту `Page` гортати список коментарів *і* фокусуватись на полі введення, коли ви натискаєте кнопку:
176176
177177
<Sandpack>
178178
@@ -285,8 +285,8 @@ export default AddComment;
285285
286286
<Pitfall>
287287
288-
**Do not overuse refs.** You should only use refs for *imperative* behaviors that you can't express as props: for example, scrolling to a node, focusing a node, triggering an animation, selecting text, and so on.
288+
**Не зловживайте рефами.** Використовуйте рефи лише для *імперативної* поведінки, яку ви не можете виразити через пропси: наприклад, пролистування до вузла DOM, фокусування на вузлі, виклик анімації, виділення тексту тощо.
289289
290-
**If you can express something as a prop, you should not use a ref.** For example, instead of exposing an imperative handle like `{ open, close }` from a `Modal` component, it is better to take `isOpen` as a prop like `<Modal isOpen={isOpen} />`. [Effects](/learn/synchronizing-with-effects) can help you expose imperative behaviors via props.
290+
**Якщо ви можете виразити щось як проп, тоді не варто використовувати реф.** Наприклад, замість передачі імперативного обробника у вигляді `{ open, close }` з компоненту `Modal`, кращим підходом буде використати проп `isOpen` у такому вигляді `<Modal isOpen={isOpen} />`. [Effects](/learn/synchronizing-with-effects) може допомогти вам задавати імперативну поведінку через пропси.
291291
292292
</Pitfall>

0 commit comments

Comments
 (0)