You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Before your components are displayed on screen, they must be rendered by React. Understanding the steps in this process will help you think about how your code executes and explain its behavior.
7
+
قبل أن يتم عرض مكوناتك في الشاشة، يجب أن يتم تصييرها بواسطة React. فهم الخطوات في هذه العملية سيساعدك على التفكير في كيفية تنفيذ الكود الخاص بك وشرح سلوكه.
8
8
9
9
</Intro>
10
10
11
11
<YouWillLearn>
12
12
13
-
*What rendering means in React
14
-
*When and why React renders a component
15
-
*The steps involved in displaying a component on screen
16
-
*Why rendering does not always produce a DOM update
13
+
*ماذا يعني التصيير في React
14
+
*متى ولماذا يقوم React بتصيير مكون
15
+
*خطوات عرض مكون في الشاشة
16
+
*لماذا التصيير لا يقدم دائمًا تحديث DOM
17
17
18
18
</YouWillLearn>
19
19
20
-
Imagine that your components are cooks in the kitchen, assembling tasty dishes from ingredients. In this scenario, React is the waiter who puts in requests from customers and brings them their orders. This process of requesting and serving UI has three steps:
20
+
تخيل أن مكوناتك طهاة في المطبخ، يطبخون وصفات لذيذة، في هذا السيناريو، React هو النادل الذي يسجل طلبات الزبائن ويقدمها لهم. هذه العملية من طلب وتقديم الواجهة لها ثلاث خطوات:
21
21
22
-
1.**Triggering**a render (delivering the guest's order to the kitchen)
23
-
2.**Rendering**the component (preparing the order in the kitchen)
24
-
3.**Committing**to the DOM (placing the order on the table)
22
+
1.**تنشيط**عملية التصيير (تسليم طلب الزبون للمطبخ)
23
+
2.**تصيير**المكون (إعداد الطلب في المطبخ)
24
+
3.**التأكيد**على DOM (وضع الطلب على الطاولة)
25
25
26
26
<IllustrationBlocksequential>
27
-
<Illustrationcaption="Trigger"alt="React as a server in a restaurant, fetching orders from the users and delivering them to the Component Kitchen."src="/images/docs/illustrations/i_render-and-commit1.png" />
28
-
<Illustrationcaption="Render"alt="The Card Chef gives React a fresh Card component."src="/images/docs/illustrations/i_render-and-commit2.png" />
29
-
<Illustrationcaption="Commit"alt="React delivers the Card to the user at their table."src="/images/docs/illustrations/i_render-and-commit3.png" />
27
+
<Illustrationcaption="تنشيط"alt="تمثل React دور خادم المطعم، تجلب الطلبات من المستخدمين وتوصلها إلى مطبخ المكونات"src="/images/docs/illustrations/i_render-and-commit1.png" />
28
+
<Illustrationcatpion="تصيير"alt="يقدم الطاهي (بطاقة Card) مكون Card جديد لـ React"src="/images/docs/illustrations/i_render-and-commit2.png" />
29
+
<Illustrationcaption="تأكيد"alt="يقدم React البطاقة للمستخدم على طاولته"src="/images/docs/illustrations/i_render-and-commit3.png" />
30
30
</IllustrationBlock>
31
31
32
-
## Step 1: Trigger a render {/*step-1-trigger-a-render*/}
2.The component's (or one of its ancestors') **state has been updated.**
36
+
1.التصيير الأوَّلِي للمكون. (initial render)
37
+
2.تم تحديث حالة المكون (أو أحد آبائه). (state)
38
38
39
-
### Initial render {/*initial-render*/}
39
+
### التصيير الأوَّلِي {/*initial-render*/}
40
40
41
-
When your app starts, you need to trigger the initial render. Frameworks and sandboxes sometimes hide this code, but it's done by calling [`createRoot`](/reference/react-dom/client/createRoot)with the target DOM node, and then calling its `render`method with your component:
41
+
عند بدء تشغيل التطبيق، تحتاج لبدء التصيير الأوَّلِي، تخفي إطارات العمل ومحررات الأكواد البسيطة هذا الكود، لكنه يتم بواسطة استدعاء [`createRoot`](/reference/react-dom/client/createRoot)مستهدفًا عنصر DOM، ثم استدعاء طريقة `render`مع المكون الخاص بك:
42
42
43
43
<Sandpack>
44
44
@@ -55,44 +55,50 @@ export default function Image() {
55
55
return (
56
56
<img
57
57
src="https://i.imgur.com/ZF6s192.jpg"
58
-
alt="'Floralis Genérica' by Eduardo Catalano: a gigantic metallic flower sculpture with reflective petals"
Try commenting out the `root.render()`call and see the component disappear!
66
+
جرب عمل تعليق على السطر الذي يستدعي `root.render()`وانظر كيف تختفي الصورة.
67
67
68
-
### Re-renders when state updates {/*re-renders-when-state-updates*/}
68
+
مثل هذا:
69
69
70
-
Once the component has been initially rendered, you can trigger further renders by updating its state with the [`set` function.](/reference/react/useState#setstate) Updating your component's state automatically queues a render. (You can imagine these as a restaurant guest ordering tea, dessert, and all sorts of things after putting in their first order, depending on the state of their thirst or hunger.)
70
+
```js
71
+
// root.render(<Image />);
72
+
```
73
+
74
+
### إعادة التصيير عند تحديث الحالة {/*re-renders-when-state-updates*/}
75
+
76
+
بمجرد أن يتم تصيير المكون لأول مرة، يمكنك تنشيط عمليات التصيير الأخرى عن طريق تحديث حالته باستخدام دالة [`set`](/reference/react/useState#setstate). تحديث حالة المكون الخاص بك يضع تلقائيًا عملية تصيير في قائمة الانتظار. (يمكنك تخيل هذه العمليات على أنها طلبات من زبون المطعم للحصول على الشاي أو الحلويات أو أي شيء آخر بعد طلبه الأول، اعتمادًا على حالة عطشه أو جوعه.)
71
77
72
78
<IllustrationBlocksequential>
73
-
<Illustrationcaption="State update..."alt="React as a server in a restaurant, serving a Card UI to the user, represented as a patron with a cursor for their head. They patron expresses they want a pink card, not a black one!"src="/images/docs/illustrations/i_rerender1.png" />
74
-
<Illustrationcaption="...triggers..."alt="React returns to the Component Kitchen and tells the Card Chef they need a pink Card."src="/images/docs/illustrations/i_rerender2.png" />
75
-
<Illustrationcaption="...render!"alt="The Card Chef gives React the pink Card."src="/images/docs/illustrations/i_rerender3.png" />
79
+
<Illustrationcaption="تحديث الحالة..."alt="React كخادم في مطعم، يقدم واجهة مستخدم بطاقة للمستخدم، ويمثل المستخدم بزبون مع مؤشر لرأسه. يعبر الزبون عن رغبته في الحصول على بطاقة وردية، وليس سوداء!"src="/images/docs/illustrations/i_rerender1.png" />
80
+
<Illustrationcaption="...يؤدي إلى..."alt="يعود React إلى مطبخ المكونات ويخبر طاهي البطاقات أنه يحتاج إلى بطاقة وردية."src="/images/docs/illustrations/i_rerender2.png" />
***عند التصيير اللاحق،**سينشئ React المكون الذي أدى تحديث حالته إلى التصيير.
84
90
85
-
This process is recursive: if the updated component returns some other component, React will render _that_ component next, and if that component also returns something, it will render _that_ component next, and so on. The process will continue until there are no more nested components and React knows exactly what should be displayed on screen.
91
+
هذه العملية تتكرر: إذا كان المكون المحدث يعيد مكونًا آخر، فسيقوم React بتصيير هذا المكون التالي، وإذا كان هذا المكون أيضًا يعيد شيئًا ما، فسيقوم بتصيير هذا المكون التالي، وهكذا. ستستمر العملية حتى لا تكون هناك مكونات متداخلة أخرى ويعرف React بالضبط ما يجب عرضه على الشاشة.
86
92
87
-
In the following example, React will call `Gallery()`and `Image()`several times:
93
+
في المثال التالي، سينفذ React `Gallery()`و `Image()`عدة مرات:
88
94
89
95
<Sandpack>
90
96
91
97
```js Gallery.js active
92
98
exportdefaultfunctionGallery() {
93
99
return (
94
100
<section>
95
-
<h1>Inspiring Sculptures</h1>
101
+
<h1>منحوتات ملهمة</h1>
96
102
<Image />
97
103
<Image />
98
104
<Image />
@@ -104,7 +110,7 @@ function Image() {
104
110
return (
105
111
<img
106
112
src="https://i.imgur.com/ZF6s192.jpg"
107
-
alt="'Floralis Genérica' by Eduardo Catalano: a gigantic metallic flower sculpture with reflective petals"
***During the initial render,** React will [create the DOM nodes](https://developer.mozilla.org/docs/Web/API/Document/createElement)for`<section>`,`<h1>`, and three`<img>` tags.
128
-
***During a re-render,**React will calculate which of their properties, if any, have changed since the previous render. It won't do anything with that information until the next step, the commit phase.
133
+
***أثناء التصيير الأولي**ستقوم React [بإنشاء عناصر DOM](https://developer.mozilla.org/docs/Web/API/Document/createElement)لعلامات`<section>`،`<h1>`، وثلاث علامات`<img>`.
134
+
***أثناء التصيير اللاحق**سيحسب الخصائص التي تغيرت منذ التصيير السابق، إن وجدت. لن يفعل أي شيء بهذه المعلومات حتى الخطوة التالية، وهي مرحلة التأكيد.
129
135
130
136
<Pitfall>
131
137
132
-
Rendering must always be a [pure calculation](/learn/keeping-components-pure):
138
+
دائمًا يجب أن يكون التصيير [محسوبًا بدقة](/learn/keeping-components-pure):
133
139
134
-
***Same inputs, same output.**Given the same inputs, a component should always return the same JSX. (When someone orders a salad with tomatoes, they should not receive a salad with onions!)
135
-
***It minds its own business.**It should not change any objects or variables that existed before rendering. (One order should not change anyone else's order.)
140
+
***إن كان نفس المدخلات يجب أن يحصل على نفس الناتج.**بالنظر إلى نفس الطلبات، يجب أن يعيد المكون نفس JSX دائمًا. (عندما يطلب شخص ما سلطة مع الطماطم، فلا ينبغي أن يتلقى سلطة مع البصل!)
141
+
***يهتم فقط بما يخصه.**لا ينبغي أن يغير أي كائنات أو متغيرات كانت موجودة قبل التصيير. (لا ينبغي أن يؤثر طلب واحد على طلبات الآخرين.)
136
142
137
-
Otherwise, you can encounter confusing bugs and unpredictable behavior as your codebase grows in complexity. When developing in "Strict Mode", React calls each component's function twice, which can help surface mistakes caused by impure functions.
143
+
وإلا، يمكنك أن تواجه أخطاءً محيّرة وسلوكًا غير متوقع مع تعقيد بيئة الكود. عند التطوير في "وضع صارم (Srrict Mode)"، ينشئ React كل وظيفة مكون مرتين، مما يساعد على كشف الأخطاء الناتجة عن الوظائف غير النقية.
The default behavior of rendering all components nested within the updated component is not optimal for performance if the updated component is very high in the tree. If you run into a performance issue, there are several opt-in ways to solve it described in the [Performance](https://reactjs.org/docs/optimizing-performance.html) section. **Don't optimize prematurely!**
151
+
التصرف الافتراضي لتصيير كل المكونات المتفرعة عن المكون الذي تم تحديثة ليس مثاليًا للأداء إذا كان المكون المحدث عاليًا جدًا في شجرة المكونات. إذا واجهتك مشكلة في الأداء، فهناك طرق مختلفة لحلها، مشروحة في قسم [الأداء](https://reactjs.org/docs/optimizing-performance.html). **لا تستعجل محاولة تحسين الأداء!**
146
152
147
153
</DeepDive>
148
154
149
-
## Step 3: React commits changes to the DOM {/*step-3-react-commits-changes-to-the-dom*/}
155
+
## الخطوة الثالثة: يؤكد React التغييرات على DOM {/*step-3-react-commits-changes-to-the-dom*/}
150
156
151
-
After rendering (calling) your components, React will modify the DOM.
157
+
بعد تصيير (استدعاء) للمكونات، سيعدل React الـ DOM.
152
158
153
-
***For the initial render,**React will use the [`appendChild()`](https://developer.mozilla.org/docs/Web/API/Node/appendChild)DOM API to put all the DOM nodes it has created on screen.
154
-
***For re-renders,** React will apply the minimal necessary operations (calculated while rendering!) to make the DOM match the latest rendering output.
159
+
***أثناء التصيير المبدئي**سيستخدمReact [DOM API `appendChild()`](https://developer.mozilla.org/docs/Web/API/Node/appendChild)لوضع جميع عناصر DOM التي أنشأها على الشاشة.
160
+
***أثناء إعادة التصيير**سينفذ React العمليات اللازمة (التي تم حسابها أثناء التصيير!) لجعل DOM يتطابق مع أحدث نتيجة تصيير.
155
161
156
-
**React only changes the DOM nodes if there's a difference between renders.**For example, here is a component that re-renders with different props passed from its parent every second. Notice how you can add some text into the `<input>`, updating its `value`, but the text doesn't disappear when the component re-renders:
162
+
**يغيّر React عناصر DOM فقط إذا كان هناك فرق بين التصييرين.**على سبيل المثال، هناك مكون يقوم بإعادة التصيير مع اختلاف الخصائص المُمَرَّرة من المكون الأصلي كل ثانية. لاحظ كيف يمكنك إضافة بعض النص إلى `<input>`، وتحديث `value`، ولكن النص لا يختفي عند إعادة تصيير المكون:
157
163
158
164
<Sandpack>
159
165
@@ -193,21 +199,22 @@ export default function App() {
193
199
194
200
</Sandpack>
195
201
196
-
This works because during this last step, React only updates the content of `<h1>` with the new `time`. It sees that the `<input>` appears in the JSX in the same place as last time, so React doesn't touch the `<input>`—or its `value`!
هذا يعمل لأنه أثناء هذه الخطوة الأخيرة، يحدّث React محتوى `<h1>` بالوقت الجديد. يرى React أن `<input>` يظهر في JSX في نفس المكان كالمرة السابقة، لذلك لا يلمس React الـ `<input>` - أو `value`!
203
+
204
+
## الخاتمة: رسم المتصفح {/*epilogue-browser-paint*/}
198
205
199
-
After rendering is done and React updated the DOM, the browser will repaint the screen. Although this process is known as "browser rendering", we'll refer to it as "painting" to avoid confusion throughout the docs.
206
+
بعد الانتهاء من التصيير وتحديث React لـ DOM، سيعيد المتصفح رسم الشاشة. على الرغم من أن هذه العملية معروفة باسم "تصيير المتصفح"، سنشير إليها باسم "رسم" طوال التوثيق لتجنب الخلط.
200
207
201
-
<Illustrationalt="A browser painting 'still life with card element'."src="/images/docs/illustrations/i_browser-paint.png" />
208
+
<Illustrationalt="رسم المتصفح: لا يزال حيًَا مع عنصر البطاقة'."src="/images/docs/illustrations/i_browser-paint.png" />
202
209
203
210
<Recap>
204
211
205
-
*Any screen update in a React app happens in three steps:
206
-
1.Trigger
207
-
2.Render
208
-
3.Commit
209
-
*You can use Strict Mode to find mistakes in your components
210
-
*React does not touch the DOM if the rendering result is the same as last time
212
+
***يحدث أي تحديث على الشاشة في تطبيق React في ثلاث خطوات:**
213
+
1.**التنشيط**
214
+
2.**التصيير**
215
+
3.**التأكيد**
216
+
*يمكنك استخدام **الوضع الصارم** للعثور على الأخطاء في مكوناتك
217
+
*لا يلمس React الـ DOM إذا كانت نتيجة التصيير هي نفسها كالمرة السابقة
0 commit comments