diff --git a/content/docs/forwarding-refs.md b/content/docs/forwarding-refs.md index 3318d8499..8fa456048 100644 --- a/content/docs/forwarding-refs.md +++ b/content/docs/forwarding-refs.md @@ -1,76 +1,78 @@ --- id: forwarding-refs -title: Forwarding Refs +title: فوروارد کردن ref ها permalink: docs/forwarding-refs.html --- -Ref forwarding is a technique for automatically passing a [ref](/docs/refs-and-the-dom.html) through a component to one of its children. This is typically not necessary for most components in the application. However, it can be useful for some kinds of components, especially in reusable component libraries. The most common scenarios are described below. +ref فوروارد کردن یک تکنیک برای ارسال خودکار یک [ref](/docs/refs-and-the-dom.html) از طریق یک کامپوننت به فرزندانش می‌باشد. این کار معمولا برای بسیاری از کامپوننت‌ها در اپلیکیشن لازم نیست. به هر حال، در بعضی از کامپوننت‌ها، به خصوص در کامپوننت‌های کتابخانه‌ای با قابلیت استفاده مجدد می‌تواند مفید باشد. رایج‌ترین حالات ممکن در ادامه شرح داده شده‌اند. -## Forwarding refs to DOM components {#forwarding-refs-to-dom-components} +## فوروارد کردن ref ها به کامپوننت‌های DOM {#forwarding-refs-to-dom-components} -Consider a `FancyButton` component that renders the native `button` DOM element: +یک کامپوننت `FancyButton` که المنت محلی `button` در DOM را رندر می‌کند در نظر بگیرید: `embed:forwarding-refs/fancy-button-simple.js` -React components hide their implementation details, including their rendered output. Other components using `FancyButton` **usually will not need to** [obtain a ref](/docs/refs-and-the-dom.html) to the inner `button` DOM element. This is good because it prevents components from relying on each other's DOM structure too much. +کامپوننت‌های ری‌اکت جزئیات پیاده سازی، شامل خروجی رندر شده خود را پنهان می‌کنند. کامپوننت‌های دیگر که از `FancyButton` استفاده می‌کنند، معمولا به [بدست آوردن یک ref](/docs/refs-and-the-dom.html) به المنت DOM `button` داخلی **نیازی نخواهند داشت** و این به علت جلوگیری از تکیه بیش از اندازه کامپوننت‌ها به ساختار DOM یک‌دیگر خوب است. -Although such encapsulation is desirable for application-level components like `FeedStory` or `Comment`, it can be inconvenient for highly reusable "leaf" components like `FancyButton` or `MyTextInput`. These components tend to be used throughout the application in a similar manner as a regular DOM `button` and `input`, and accessing their DOM nodes may be unavoidable for managing focus, selection, or animations. +اگرچه چنین کپسوله‌سازی برای کامپوننت‌هایی در سطح اپ مانند `FeedStory` یا `Comment` مطلوب است، برای کامپوننت‌های کوچک که قابلیت استفاده مجدد بسیار زیادی دارند مانند `FancyButton` یا `MyTextInput` نامناسب می‌باشد. این کامپوننت‌ها میل به استفاده شدن در اپ به یک شیوه مشابه به عنوان یک `button` و `input` معمولی DOM دارند و دسترسی به نودهای DOM آن ها برای مدیریت انیمیشن‌ها، focus و selection ممکن است اجتناب ناپذیر باشد. -**Ref forwarding is an opt-in feature that lets some components take a `ref` they receive, and pass it further down (in other words, "forward" it) to a child.** +**فوروارد کردن ref یک قابلیت انتخابی است که به بعضی کامپوننت ها اجازه گرفتن یک `ref` و انتقال آن به فرزندان (به عبارت دیگر, "فوروارد کردن" آن) را می‌دهد.** -In the example below, `FancyButton` uses `React.forwardRef` to obtain the `ref` passed to it, and then forward it to the DOM `button` that it renders: +در مثال زیر، `FancyButton` از `React.forwardRef` برای گرفتن `ref` که به آن منتقل شده استفاده می‌کند، و سپس آن را به `button` DOM که رندر می‌کند فوروارد می‌کند. `embed:forwarding-refs/fancy-button-simple-ref.js` -This way, components using `FancyButton` can get a ref to the underlying `button` DOM node and access it if necessary—just like if they used a DOM `button` directly. +با این روش، کامپوننت‌هایی که از `FancyButton` استفاده می‌کنند، می‌توانند یک ref به نود `button` در DOM بگیرند و در صورت نیاز، به همان شکلی که از یک `button` در DOM مستقیما استفاده می کنند، از این کامپوننت نیز بهره ببرند. -Here is a step-by-step explanation of what happens in the above example: +در زیر، یک توضیح مرحله به مرحله از آن‌چه در مثال بالا اتفاق افتاده است را مشاهده می‌نمایید: -1. We create a [React ref](/docs/refs-and-the-dom.html) by calling `React.createRef` and assign it to a `ref` variable. -1. We pass our `ref` down to `` by specifying it as a JSX attribute. -1. React passes the `ref` to the `(props, ref) => ...` function inside `forwardRef` as a second argument. -1. We forward this `ref` argument down to `