Skip to content
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
da72216
Translate page "rendering-elements.md"
sorousht Mar 1, 2019
3103ea8
Improve translation of content/docs/rendering-elements.md
sJJdGG Mar 3, 2019
49f0334
Improve translation of content/docs/rendering-elements.md
sJJdGG Mar 3, 2019
4df2796
Improve the translation of content/docs/rendering-elements.md
sJJdGG Mar 3, 2019
9c81820
Apply @sJJdGG comment on content/docs/rendering-elements.md page
sJJdGG Mar 3, 2019
8e821ad
Fix a translation issue in content/docs/rendering-elements.md
sJJdGG Mar 3, 2019
50c09fd
Fix a mistake in translating content/docs/rendering-elements.md
sJJdGG Mar 4, 2019
7c2dab1
Fix a mistake in translation of content/docs/rendering-elements.md
sJJdGG Mar 4, 2019
4c39503
Improve translation of content/docs/rendering-elements.md
sJJdGG Mar 4, 2019
511730c
Improve translation of content/docs/rendering-elements.md
sJJdGG Mar 4, 2019
ca5a0a4
Fix some issues in translation of content/docs/rendering-elements.md
sJJdGG Mar 4, 2019
4f3aff4
Enhance the translation of content/docs/rendering-elements.md
sJJdGG Mar 4, 2019
fd7bf42
Apply a fix to improve translation of content/docs/rendering-elements.md
sJJdGG Mar 4, 2019
9f3e4d4
Improve translation of content/docs/rendering-elements.md
sJJdGG Mar 4, 2019
782b2f8
Enhance translation of content/docs/rendering-elements.md page
sJJdGG Mar 4, 2019
6bb920b
Update content/docs/rendering-elements.md
sJJdGG Mar 4, 2019
2a9bd67
Apply a fix suggested by @sJJdGG in translation of content/docs/rende…
sJJdGG Mar 4, 2019
d6e041e
Update content/docs/rendering-elements.md
sJJdGG Mar 4, 2019
d52f2f8
Fix a mistake in content/docs/rendering-elements.md
sJJdGG Mar 4, 2019
79cb224
Use a better word for "element"
sorousht Mar 5, 2019
ac5dd4f
Enhance translation of content/docs/rendering-elements.md
sJJdGG Mar 6, 2019
614a32d
Enhance translation of content/docs/rendering-elements.md
sJJdGG Mar 6, 2019
4e2ce4e
Update content/docs/rendering-elements.md
sJJdGG Mar 6, 2019
426f597
Improve translation of content/docs/rendering-elements.md
sJJdGG Mar 6, 2019
b06a454
Fix a minor word replacement in content/docs/rendering-elements.md
sJJdGG Mar 7, 2019
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
56 changes: 29 additions & 27 deletions content/docs/rendering-elements.md
Original file line number Diff line number Diff line change
@@ -1,75 +1,77 @@
---
id: rendering-elements
title: Rendering Elements
title: رندر کردن المنت‌ها
permalink: docs/rendering-elements.html
redirect_from:
- "docs/displaying-data.html"
prev: introducing-jsx.html
next: components-and-props.html
---

Elements are the smallest building blocks of React apps.
المنت‌ها (elements) کوچک‌ترین جزء تشکیل‌دهنده برنامه‌های ری‌اکتی هستند.

An element describes what you want to see on the screen:
یک المنت آن‌ چیزی را که شما می‌خواهید روی صفحه ببینید توصیف میکند:

```js
const element = <h1>Hello, world</h1>;
```

Unlike browser DOM elements, React elements are plain objects, and are cheap to create. React DOM takes care of updating the DOM to match the React elements.
برخلاف المنت‌های ‌DOM مرورگر، المنت‌های ری‌اکت اشیاء ساده‌ای هستند که ایجاد آن‌ها هزینه چندانی ندارد. وظیفه ری‌اکت DOM به‌روز رسانی DOM است و اطمینان از این‌که دقیقا با المنت‌های ری‌اکت یکسان باشد.

>**Note:**
>**نکته:**
>
>One might confuse elements with a more widely known concept of "components". We will introduce components in the [next section](/docs/components-and-props.html). Elements are what components are "made of", and we encourage you to read this section before jumping ahead.
>ممکن است بعضی‌ها المنت‌ها را با "کامپوننت‌ها" (مفهومی که بیشتر جا افتاده‌است.) اشتباه بگیرند. ما کامپوننت‌ها را در [بخش بعدی](/docs/components-and-props.html) معرفی خواهیم‌کرد. المنت‌ها اجزائی هستند که کامپوننت‌ها از آن ساخته می‌شوند و ما به شما پیشنهاد می‌کنیم که پیش از رفتن به بخش بعدی، حتما این بخش را مطالعه کنید.

## Rendering an Element into the DOM {#rendering-an-element-into-the-dom}
## رندر کردن یک المنت درون DOM {#rendering-an-element-into-the-dom}

Let's say there is a `<div>` somewhere in your HTML file:
فرض کنید یک `<div>` جایی در فایل HTML شما قرار دارد:

```html
<div id="root"></div>
```

We call this a "root" DOM node because everything inside it will be managed by React DOM.
ما این المنت‌ را یک DOM node "ریشه" نامگذاری می‌کنیم، به این دلیل‌ که هر چیزی که داخل آن قرار گیرد، توسط ری‌اکت DOM مدیریت می‌شود.

Applications built with just React usually have a single root DOM node. If you are integrating React into an existing app, you may have as many isolated root DOM nodes as you like.
برنامه‌هایی که فقط با ری‌اکت ساخته می‌شوند، معمولا فقط یک DOM node ریشه دارند. اگر ری‌اکت را به یک برنامه موجود اضافه کنید، می‌توانید هر تعدادی از DOM node های ریشه‌ی ایزوله که بخواهید داشته‌باشید.

برای رندر کردن یک المنت ری‌اکت درون یک DOM node ریشه، هر دو را به `ReactDOM.render()` بدهید

To render a React element into a root DOM node, pass both to `ReactDOM.render()`:

`embed:rendering-elements/render-an-element.js`

[](codepen://rendering-elements/render-an-element)
[با CodePen امتحان کنید](codepen://rendering-elements/render-an-element)

این کد روی صفحه "Hello, world" را نمایش می‌دهد.

It displays "Hello, world" on the page.
## به‌روز‌رسانی المنت رندر شده {#updating-the-rendered-element}

## Updating the Rendered Element {#updating-the-rendered-element}
المنت‌های ری‌اکت [تغییر ناپدیر](https://en.wikipedia.org/wiki/Immutable_object) هستند. زمانی که یک المنت را ایجاد می‌کنید، دیگر قادر به تغییر فرزندان یا خصوصیات آن نخواهید بود. یک المنت را مانند یک فریم از یک فیلم تصور کنید که UI را در یک نقطه زمانی مشخص نشان می‌دهد.

React elements are [immutable](https://en.wikipedia.org/wiki/Immutable_object). Once you create an element, you can't change its children or attributes. An element is like a single frame in a movie: it represents the UI at a certain point in time.
با اطلاعاتی که تا این‌جا به‌دست آورده‌ایم، تنها راه به‌روز رسانی UI این است که یک المنت جدید ساخته و آن را به تابع `ReactDOM.render()` بدهیم.

With our knowledge so far, the only way to update the UI is to create a new element, and pass it to `ReactDOM.render()`.

Consider this ticking clock example:
این مثال ساعت را درنظر بگیرید:

`embed:rendering-elements/update-rendered-element.js`

[](codepen://rendering-elements/update-rendered-element)
[با CodePen امتحان کنید](codepen://rendering-elements/update-rendered-element)

It calls `ReactDOM.render()` every second from a [`setInterval()`](https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setInterval) callback.
در این مثال تابع `ReactDOM.render()` هربار توسط callback تابع [`()setInterval`](https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setInterval) فراخوانی می‌شود.

>**Note:**
>**نکته:**
>
>In practice, most React apps only call `ReactDOM.render()` once. In the next sections we will learn how such code gets encapsulated into [stateful components](/docs/state-and-lifecycle.html).
> در عمل، بیشتر برنامه‌های ری‌اکت تنها یک بار `ReactDOM.render()` را فراخوانی می‌کنند. در بخش‌های بعدی یاد می‌گیریم که چگونه چنین کد‌هایی به صورت [کامپوننت‌های دارای state](/docs/state-and-lifecycle.html) کپسوله می‌شوند.
>
>We recommend that you don't skip topics because they build on each other.
> از آن‌جا که هر بخش با استناد به موضوع‌های پیشین نوشته‌ شده‌است، پیشنهاد می‌کنیم هیچ موضوعی را از قلم نیندازید.

## React Only Updates What's Necessary {#react-only-updates-whats-necessary}
## ری‌اکت تنها چیز‌هایی که نیاز‌ هست را به‌روز رسانی می‌کند {#react-only-updates-whats-necessary}

React DOM compares the element and its children to the previous one, and only applies the DOM updates necessary to bring the DOM to the desired state.
ری‌اکت DOM المنت موردنظر و فرزندانش را با حالت پیشین آن مقایسه می‌کند و تنها به‌روز رسانی‌های DOM مورد نیاز را اعمال می‌کند تا ‌DOM را به وضعیت موردنظر برساند.

You can verify by inspecting the [last example](codepen://rendering-elements/update-rendered-element) with the browser tools:
برای اطمینان، [مثال قبلی](codepen://rendering-elements/update-rendered-element) را با استفاده از ابزارهای مرورگر بررسی کنید:

![DOM inspector showing granular updates](../images/docs/granular-dom-updates.gif)

Even though we create an element describing the whole UI tree on every tick, only the text node whose contents has changed gets updated by React DOM.
با وجود این‌که ما هر ثانیه یک المنت که توصیف‌کننده کل UI است را ایجاد می‌کنیم، فقط node متنی که محتویاتش تغییر کرده‌است توسط ری‌اکت DOM به‌روز‌رسانی می‌شود.

In our experience, thinking about how the UI should look at any given moment rather than how to change it over time eliminates a whole class of bugs.
براساس تجربه ما، تفکر درباره این‌که UI در یک زمان مشخص چگونه به نظر بیاید، به جای این‌که چگونه آن را در طول زمان تغییر دهیم، یک دسته کامل از باگ‌ها را از بین می‌برد.