Skip to content

Commit 8304060

Browse files
authored
Merge pull request #478 from A7med3bdulBaset/render-and-commit
[Done] Translate `Render and Commit`
2 parents 9fbc364 + 2ac89af commit 8304060

File tree

2 files changed

+65
-58
lines changed

2 files changed

+65
-58
lines changed
Lines changed: 64 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
11
---
2-
title: Render and Commit
2+
title: التصيير والتأكيد
33
---
44

55
<Intro>
66

7-
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. فهم الخطوات في هذه العملية سيساعدك على التفكير في كيفية تنفيذ الكود الخاص بك وشرح سلوكه.
88

99
</Intro>
1010

1111
<YouWillLearn>
1212

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
1717

1818
</YouWillLearn>
1919

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 هو النادل الذي يسجل طلبات الزبائن ويقدمها لهم. هذه العملية من طلب وتقديم الواجهة لها ثلاث خطوات:
2121

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 (وضع الطلب على الطاولة)
2525

2626
<IllustrationBlock sequential>
27-
<Illustration caption="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-
<Illustration caption="Render" alt="The Card Chef gives React a fresh Card component." src="/images/docs/illustrations/i_render-and-commit2.png" />
29-
<Illustration caption="Commit" alt="React delivers the Card to the user at their table." src="/images/docs/illustrations/i_render-and-commit3.png" />
27+
<Illustration caption="تنشيط" alt="تمثل React دور خادم المطعم، تجلب الطلبات من المستخدمين وتوصلها إلى مطبخ المكونات" src="/images/docs/illustrations/i_render-and-commit1.png" />
28+
<Illustration catpion="تصيير" alt="يقدم الطاهي (بطاقة Card) مكون Card جديد لـ React" src="/images/docs/illustrations/i_render-and-commit2.png" />
29+
<Illustration caption="تأكيد" alt="يقدم React البطاقة للمستخدم على طاولته" src="/images/docs/illustrations/i_render-and-commit3.png" />
3030
</IllustrationBlock>
3131

32-
## Step 1: Trigger a render {/*step-1-trigger-a-render*/}
32+
## الخطوة الأولى: تنشيط التصيير {/*step-1-trigger-a-render*/}
3333

34-
There are two reasons for a component to render:
34+
هناك سببان لتنفيذ تصيير المكون:
3535

36-
1. It's the component's **initial render.**
37-
2. The component's (or one of its ancestors') **state has been updated.**
36+
1. التصيير الأوَّلِي للمكون. (initial render)
37+
2. تم تحديث حالة المكون (أو أحد آبائه). (state)
3838

39-
### Initial render {/*initial-render*/}
39+
### التصيير الأوَّلِي {/*initial-render*/}
4040

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` مع المكون الخاص بك:
4242

4343
<Sandpack>
4444

@@ -55,44 +55,50 @@ export default function Image() {
5555
return (
5656
<img
5757
src="https://i.imgur.com/ZF6s192.jpg"
58-
alt="'Floralis Genérica' by Eduardo Catalano: a gigantic metallic flower sculpture with reflective petals"
58+
alt="'Floralis Generica' لإدواردو كاتالانو: منحوتة زهرة معدنية عملاقة بتلات عاكسة للضوء"
5959
/>
6060
);
6161
}
6262
```
6363

6464
</Sandpack>
6565

66-
Try commenting out the `root.render()` call and see the component disappear!
66+
جرب عمل تعليق على السطر الذي يستدعي `root.render()` وانظر كيف تختفي الصورة.
6767

68-
### Re-renders when state updates {/*re-renders-when-state-updates*/}
68+
مثل هذا:
6969

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). تحديث حالة المكون الخاص بك يضع تلقائيًا عملية تصيير في قائمة الانتظار. (يمكنك تخيل هذه العمليات على أنها طلبات من زبون المطعم للحصول على الشاي أو الحلويات أو أي شيء آخر بعد طلبه الأول، اعتمادًا على حالة عطشه أو جوعه.)
7177

7278
<IllustrationBlock sequential>
73-
<Illustration caption="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-
<Illustration caption="...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-
<Illustration caption="...render!" alt="The Card Chef gives React the pink Card." src="/images/docs/illustrations/i_rerender3.png" />
79+
<Illustration caption="تحديث الحالة..." alt="React كخادم في مطعم، يقدم واجهة مستخدم بطاقة للمستخدم، ويمثل المستخدم بزبون مع مؤشر لرأسه. يعبر الزبون عن رغبته في الحصول على بطاقة وردية، وليس سوداء!" src="/images/docs/illustrations/i_rerender1.png" />
80+
<Illustration caption="...يؤدي إلى..." alt="يعود React إلى مطبخ المكونات ويخبر طاهي البطاقات أنه يحتاج إلى بطاقة وردية." src="/images/docs/illustrations/i_rerender2.png" />
81+
<Illustration caption="...تصيير!" alt="يعطي طاهي البطاقات React البطاقة الوردية." src="/images/docs/illustrations/i_rerender3.png" />
7682
</IllustrationBlock>
7783

78-
## Step 2: React renders your components {/*step-2-react-renders-your-components*/}
84+
## الخطوة الثانية: يقوم React بتصيير مكوناتك {/*step-2-react-renders-your-components*/}
7985

80-
After you trigger a render, React calls your components to figure out what to display on screen. **"Rendering" is React calling your components.**
86+
بعد تنشيط عملية التصيير، يقوم React بتصيير مكوناتك لمعرفة ما يجب عرضه على الشاشة. **"التصيير" هو استدعاء React لمكوناتك.**
8187

82-
* **On initial render,** React will call the root component.
83-
* **For subsequent renders,** React will call the function component whose state update triggered the render.
88+
* **عند التصيير الأوَّلِي،** سينشئ React المكون الأصل.
89+
* **عند التصيير اللاحق،** سينشئ React المكون الذي أدى تحديث حالته إلى التصيير.
8490

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 بالضبط ما يجب عرضه على الشاشة.
8692

87-
In the following example, React will call `Gallery()` and `Image()` several times:
93+
في المثال التالي، سينفذ React `Gallery()` و `Image()` عدة مرات:
8894

8995
<Sandpack>
9096

9197
```js Gallery.js active
9298
export default function Gallery() {
9399
return (
94100
<section>
95-
<h1>Inspiring Sculptures</h1>
101+
<h1>منحوتات ملهمة</h1>
96102
<Image />
97103
<Image />
98104
<Image />
@@ -104,7 +110,7 @@ function Image() {
104110
return (
105111
<img
106112
src="https://i.imgur.com/ZF6s192.jpg"
107-
alt="'Floralis Genérica' by Eduardo Catalano: a gigantic metallic flower sculpture with reflective petals"
113+
alt="'Floralis Generica' لإدواردو كاتالانو: منحوتة زهرة معدنية عملاقة بتلات عاكسة للضوء"
108114
/>
109115
);
110116
}
@@ -124,36 +130,36 @@ img { margin: 0 10px 10px 0; }
124130

125131
</Sandpack>
126132

127-
* **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+
* **أثناء التصيير اللاحق** سيحسب الخصائص التي تغيرت منذ التصيير السابق، إن وجدت. لن يفعل أي شيء بهذه المعلومات حتى الخطوة التالية، وهي مرحلة التأكيد.
129135

130136
<Pitfall>
131137

132-
Rendering must always be a [pure calculation](/learn/keeping-components-pure):
138+
دائمًا يجب أن يكون التصيير [محسوبًا بدقة](/learn/keeping-components-pure):
133139

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+
* **يهتم فقط بما يخصه.** لا ينبغي أن يغير أي كائنات أو متغيرات كانت موجودة قبل التصيير. (لا ينبغي أن يؤثر طلب واحد على طلبات الآخرين.)
136142

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 كل وظيفة مكون مرتين، مما يساعد على كشف الأخطاء الناتجة عن الوظائف غير النقية.
138144

139145
</Pitfall>
140146

141147
<DeepDive>
142148

143-
#### Optimizing performance {/*optimizing-performance*/}
149+
#### تحسين الأداء {/*optimizing-performance*/}
144150

145-
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). **لا تستعجل محاولة تحسين الأداء!**
146152

147153
</DeepDive>
148154

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*/}
150156

151-
After rendering (calling) your components, React will modify the DOM.
157+
بعد تصيير (استدعاء) للمكونات، سيعدل React الـ DOM.
152158

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 يتطابق مع أحدث نتيجة تصيير.
155161

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`، ولكن النص لا يختفي عند إعادة تصيير المكون:
157163

158164
<Sandpack>
159165

@@ -193,21 +199,22 @@ export default function App() {
193199

194200
</Sandpack>
195201

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`!
197-
## Epilogue: Browser paint {/*epilogue-browser-paint*/}
202+
هذا يعمل لأنه أثناء هذه الخطوة الأخيرة، يحدّث React محتوى `<h1>` بالوقت الجديد. يرى React أن `<input>` يظهر في JSX في نفس المكان كالمرة السابقة، لذلك لا يلمس React الـ `<input>` - أو `value`!
203+
204+
## الخاتمة: رسم المتصفح {/*epilogue-browser-paint*/}
198205

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، سيعيد المتصفح رسم الشاشة. على الرغم من أن هذه العملية معروفة باسم "تصيير المتصفح"، سنشير إليها باسم "رسم" طوال التوثيق لتجنب الخلط.
200207

201-
<Illustration alt="A browser painting 'still life with card element'." src="/images/docs/illustrations/i_browser-paint.png" />
208+
<Illustration alt="رسم المتصفح: لا يزال حيًَا مع عنصر البطاقة'." src="/images/docs/illustrations/i_browser-paint.png" />
202209

203210
<Recap>
204211

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 إذا كانت نتيجة التصيير هي نفسها كالمرة السابقة
211218

212219
</Recap>
213220

src/sidebarLearn.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
"path": "/learn/state-a-components-memory"
100100
},
101101
{
102-
"title": "Render and Commit",
102+
"title": "التصيير والتأكيد",
103103
"path": "/learn/render-and-commit"
104104
},
105105
{

0 commit comments

Comments
 (0)