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
Copy file name to clipboardExpand all lines: src/content/learn/your-first-component.md
+48-49Lines changed: 48 additions & 49 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,7 +33,7 @@ title: مكوّنك الأول
33
33
34
34
يمثل هذا الترميز المرئي هذه المقالة `<article>`, عنوانها `<h1>`, وفهرس محتويات مختصر في شكل قائمة مرتبة `<ol>`. ترميز مرئي كهذا, مدمج مع CSS من أجل الأنماط التصميمية, و JavaScript من أجل التفاعلية, يكمن وراء كل شريط جانبي, صورة رمزية, نافذة, قائمة منسدلة - كل قطعة من واجهة مستخدم تراها في الويب.
35
35
36
-
تمكنك React من دمج الترميز المرئي, وCSS, وJavaScript في "مكونات" مخصصة, **عناصر واجهة المستخدم قابلة لإعادة الاستخدام لتطبيقك**. يمكن تحويل كود فهرس المحتوى الذي رأيته أعلاه الى مكوّن `<TableOfContents />` الذي يمكن تصييره في كل صفحة. لا يزال يستخدم هذا المكوّن تحت الخطاء وسوم مثل `<article>`, `<h1>`, إلخ.
36
+
تمكنك React من دمج الترميز المرئي, وCSS, وJavaScript في "مكونات" مخصصة, **عناصر واجهة المستخدم قابلة لإعادة الاستخدام لتطبيقك**. يمكن تحويل كود فهرس المحتوى الذي رأيته أعلاه إلى مكوّن `<TableOfContents />` الذي يمكن تصييره في كل صفحة. لا يزال يستخدم هذا المكوّن تحت الخطاء وسوم مثل `<article>`, `<h1>`, إلخ.
37
37
38
38
تمامًا مثل الوسوم HTML، يمكنك تجميع وترتيب وتضمين المكوّنات لتصميم صفحات كاملة. على سبيل المثال، صفحة المستندات التي تقرأها مصنوعة من مكوّنات React.
39
39
@@ -51,7 +51,7 @@ title: مكوّنك الأول
51
51
</PageLayout>
52
52
```
53
53
54
-
مع نمو مشروعك, ستلاحظ انه يمكن تجميع العديد من تصاميمك بواسطة إعادة استخدام مكوّنات كتبتها مسبقا, مما يسرع عملية التطوير. يمكن إضافة فهرس المحتويات أعلاه الى أي شاشة عن طريق `<TableOfContents />`! يمكنك أيضا الإنطلاق بسرعة في مشروعك باستخدام آلاف المكوّنات المشتركة من قبل مجتمع React مفتوحة المصدر مثل [Chakra UI](https://chakra-ui.com/) و [Material UI.](https://material-ui.com/).
54
+
مع نمو مشروعك, ستلاحظ انه يمكن تجميع العديد من تصاميمك بواسطة إعادة استخدام مكوّنات كتبتها مسبقا, مما يسرع عملية التطوير. يمكن إضافة فهرس المحتويات أعلاه إلى أي شاشة عن طريق `<TableOfContents />`! يمكنك أيضا الإنطلاق بسرعة في مشروعك باستخدام آلاف المكوّنات المشتركة من قبل مجتمع React مفتوحة المصدر مثل [Chakra UI](https://chakra-ui.com/) و [Material UI.](https://material-ui.com/).
Components are regular JavaScript functions, so you can keep multiple components in the same file. This is convenient when components are relatively small or tightly related to each other. If this file gets crowded, you can always move `Profile`to a separate file. You will learn how to do this shortly on the [page about imports.](/learn/importing-and-exporting-components)
175
+
المكوّنات هي دوال JavaScript عادية، لذا يمكنك الاحتفاظ بعدة مكوّنات في نفس الملف. هذا مناسب عندما تكون المكوّنات صغيرة نسبيًا أو تتعلق بشكل وثيق ببعضها البعض. إذا أصبح الملف مكتظًا، يمكنك دائمًا نقل المكوّن `Profile`إلى ملف منفصل. ستتعلم كيفية فعل ذلك قريبًا في [الصفحة التي تتحدث عن الاستيرادات.](/learn/importing-and-exporting-components).
178
176
179
-
Because the `Profile`components are rendered inside`Gallery`—even several times!—we can say that `Gallery`is a **parent component,** rendering each `Profile`as a "child". This is part of the magic of React: you can define a component once, and then use it in as many places and as many times as you like.
177
+
نظرًا لأن مكوّنات `Profile`يتم تصييرها داخل مكوّن`Gallery` - وحتى لعدة مرات! - يمكننا القول بأن مكون `Gallery`هو **المكوّن الأب**، الذي يقوم بتصيير كل مكوّن `Profile`كـ "ابن" . هذا جزء من سحر React: يمكنك تعريف مكوّن مرة واحدة، ثم استخدامه في العديد من الأماكن وفي العديد من الأحيان كما تريد.
180
178
181
179
<Pitfall>
182
180
183
-
Components can render other components, but**you must never nest their definitions:**
181
+
يمكن للمكوّنات عرض مكوّنات أخرى، ولكن**يجب ألا تقوم أبدا بتضمين تعريفها داخل بعضها البعض**.
184
182
185
183
```js {2-5}
186
184
exportdefaultfunctionGallery() {
187
-
// 🔴 Never define a component inside another component!
185
+
// 🔴 لا تقم أبدا بتعريف مكوّن داخل مكوّن اخر
188
186
functionProfile() {
189
187
// ...
190
188
}
191
189
// ...
192
190
}
193
191
```
194
192
195
-
The snippet above is [very slow and causes bugs.](/learn/preserving-and-resetting-state#different-components-at-the-same-position-reset-state)Instead, define every component at the top level:
193
+
الكود السابق [بطيء جدًا ويسبب أخطاء.](/learn/preserving-and-resetting-state#different-components-at-the-same-position-reset-state)بدلاً من ذلك، قم بتعريف كل مكوّن على المستوى الأعلى
196
194
197
195
```js {5-8}
198
196
exportdefaultfunctionGallery() {
199
197
// ...
200
198
}
201
199
202
-
// ✅ Declare components at the top level
200
+
// ✅ قم بتعريف المكوّنات على المستوى الأعلى
203
201
functionProfile() {
204
202
// ...
205
203
}
206
204
```
207
205
208
-
When a child component needs some data from a parent, [pass it by props](/learn/passing-props-to-a-component)instead of nesting definitions.
206
+
عندما يحتاج المكوّن الابن إلى الحصول على بعض البيانات من المكوّن الأب، يتم [تمريرها كخواص](/learn/passing-props-to-a-component)بدلاً من تضمين تعريفاتها.
209
207
210
208
</Pitfall>
211
209
212
210
<DeepDive>
213
211
214
-
#### Components all the way down {/*components-all-the-way-down*/}
212
+
#### مكوّنات على طول الطريق {/*components-all-the-way-down*/}
215
213
216
-
Your React application begins at a "root" component. Usually, it is created automatically when you start a new project. For example, if you use [CodeSandbox](https://codesandbox.io/)or[Create React App](https://create-react-app.dev/), the root component is defined in `src/App.js`. If you use the framework[Next.js](https://nextjs.org/), the root component is defined in `pages/index.js`. In these examples, you've been exporting root components.
214
+
يبدأ تطبيق React الخاص بك في مكوّن "الجذر". عادةً ما يتم إنشاؤه تلقائيًا عند بدء مشروع جديد. على سبيل المثال، إذا كنت تستخدم [CodeSandbox](https://codesandbox.io/)أو[Create React App](https://create-react-app.dev/)، يتم تعريف مكون الجذر في `src/App.js`. إذا كنت تستخدم إطار العمل[Next.js](https://nextjs.org/)، يتم تعريف مكون الجذر في `pages/index.js`. في هذه الأمثلة، كنت تقوم بتصدير مكونات الجذر.
217
215
218
-
Most React apps use components all the way down. This means that you won't only use components for reusable pieces like buttons, but also for larger pieces like sidebars, lists, and ultimately, complete pages! Components are a handy way to organize UI code and markup, even if some of them are only used once.
216
+
معظم تطبيقات React تستخدم مكوّنات على طول الطريق. وهذا يعني أنك لن تستخدم المكونات فقط للأجزاء القابلة لإعادة الاستخدام مثل الأزرار، ولكن أيضًا للأجزاء الأكبر مثل الأشرطة الجانبية، والقوائم، وفي النهاية، الصفحات الكاملة! المكوّنات هي وسيلة مفيدة لتنظيم كود واجهة المستخدم والترميز المرئي، حتى لو كان بعضها لا يستخدم سوى مرة واحدة.
219
217
220
-
[React-based frameworks](/learn/start-a-new-react-project)take this a step further. Instead of using an empty HTML file and letting React "take over" managing the page with JavaScript, they *also* generate the HTML automatically from your React components. This allows your app to show some content before the JavaScript code loads.
218
+
[أطر العمل المبنية على React](/learn/start-a-new-react-project)تأخذ خطوة إضافية. بحيث بدلاً من استخدام ملف HTML فارغ والسماح لـ React بـ "الاستيلاء" على إدارة الصفحة بواسطة JavaScript، فإنها *أيضًا* تقوم بتوليد كود الـ HTML تلقائيًا من مكوّنات React الخاصة بك. هذا يسمح لتطبيقك بعرض بعض المحتوى قبل تحميل كود JavaScript.
221
219
222
-
Still, many websites only use React to [add interactivity to existing HTML pages.](/learn/add-react-to-an-existing-project#using-react-for-a-part-of-your-existing-page)They have many root components instead of a single one for the entire page. You can use as much—or as little—React as you need.
220
+
ومع ذلك، لا تزال هناك العديد من المواقع التي تستخدم React فقط [لإضافة التفاعلية إلى صفحات HTML الموجودة مسبقا.](/learn/add-react-to-an-existing-project#using-react-for-a-part-of-your-existing-page)فلديها العديد من المكوّنات الجذرية بدلاً من وجود مكوّن جذر واحد للصفحة بأكملها. يمكنك استخدام React بالمقدار الذي تحتاج إليه.
223
221
224
222
</DeepDive>
225
223
226
224
<Recap>
227
225
228
-
You've just gotten your first taste of React! Let's recap some key points.
226
+
لقد حصلت للتو على لمحة أولى عن React! دعنا نلخص بعض النقاط الرئيسية.
229
227
230
-
* React lets you create components, **reusable UI elements for your app.**
231
-
*In a React app, every piece of UI is a component.
232
-
* React components are regular JavaScript functions except:
228
+
*تمكنك React من إنشاء مكوّنات, **عناصر واجهة المستخدم قابلة لإعادة الاستخدام لتطبيقك**
229
+
*في تطبيق React, كل قطعة من واجهة المستخدم تمثل مكوّن
230
+
*مكوّنات React هي عبارة عن دوال JavaScript عادية ما عدا أن:
233
231
234
-
1.Their names always begin with a capital letter.
235
-
2.They return JSX markup.
232
+
1.إسمهم يبدأ دائما بحرف كبير.
233
+
2.تقوم بإرجاع ترميز مرئي JSX
236
234
237
235
</Recap>
238
236
239
237
<Challenges>
240
238
241
-
#### Export the component {/*export-the-component*/}
239
+
#### قم بتصدير المكوّن {/*export-the-component*/}
242
240
243
-
This sandbox doesn't work because the root component is not exported:
241
+
هذا الكود لا يعمل لأن المكوّن الجذري لم يتم تصديره
244
242
245
243
<Sandpack>
246
244
@@ -249,7 +247,7 @@ function Profile() {
249
247
return (
250
248
<img
251
249
src="https://i.imgur.com/lICfvbD.jpg"
252
-
alt="Aklilu Lemma"
250
+
alt="أكليلو ليما"
253
251
/>
254
252
);
255
253
}
@@ -261,11 +259,11 @@ img { height: 181px; }
261
259
262
260
</Sandpack>
263
261
264
-
Try to fix it yourself before looking at the solution!
262
+
حاول إصلاحه بنفسك قبل أن تلقي نظرة على الحل!
265
263
266
264
<Solution>
267
265
268
-
Add `export default`before the function definition like so:
266
+
قم بإضافة `export default`قبل تعريف الدالة بهذا الشكل:
269
267
270
268
<Sandpack>
271
269
@@ -274,7 +272,8 @@ export default function Profile() {
274
272
return (
275
273
<img
276
274
src="https://i.imgur.com/lICfvbD.jpg"
277
-
alt="Aklilu Lemma"
275
+
alt="أكليلو ليما"
276
+
278
277
/>
279
278
);
280
279
}
@@ -286,17 +285,17 @@ img { height: 181px; }
286
285
287
286
</Sandpack>
288
287
289
-
You might be wondering why writing `export`alone is not enough to fix this example. You can learn the difference between `export`and`export default`in [Importing and Exporting Components.](/learn/importing-and-exporting-components)
288
+
قد تتساءل لماذا كتابة `export`بمفردها ليس كافيًا لإصلاح هذا المثال. يمكنك معرفة الفرق بين `export`و`export default`في قسم [استيراد وتصدير المكوّنات.](/learn/importing-and-exporting-components)
290
289
291
290
</Solution>
292
291
293
-
#### Fix the return statement {/*fix-the-return-statement*/}
Something isn't right about this `return`statement. Can you fix it?
294
+
هناك شي غير صحيح في جملة`return`هذه. هل يمكنك إصلاحه؟
296
295
297
296
<Hint>
298
297
299
-
You may get an "Unexpected token" error while trying to fix this. In that case, check that the semicolon appears *after* the closing parenthesis. Leaving a semicolon inside`return ( )`will cause an error.
298
+
قد تحصل على خطأ "Unexpected token" أثناء محاولتك لإصلاح هذا. في هذه الحالة، تحقق من أن الفاصلة المنقوطة تظهر *بعد* قوس الإغلاق. ترك فاصلة منقوطة داخل`return ( )`سيسبب خطأ.
300
299
301
300
</Hint>
302
301
@@ -305,7 +304,7 @@ You may get an "Unexpected token" error while trying to fix this. In that case,
Or by wrapping the returned JSX markup in parentheses that open right after `return`:
335
+
أو عن طريق إحاطة الترميز المرئي JSX الذي يتم إرجاعه بالأقواس ووضع علامة القوس المفتوحة مباشرة بعد الكلمة `return`.
337
336
338
337
<Sandpack>
339
338
@@ -342,7 +341,7 @@ export default function Profile() {
342
341
return (
343
342
<img
344
343
src="https://i.imgur.com/jA8hHMpm.jpg"
345
-
alt="Katsuko Saruhashi"
344
+
alt="كاتسوكو ساروهاشي"
346
345
/>
347
346
);
348
347
}
@@ -356,9 +355,9 @@ img { height: 180px; }
356
355
357
356
</Solution>
358
357
359
-
#### Spot the mistake {/*spot-the-mistake*/}
358
+
#### اكتشف الخطأ {/*spot-the-mistake*/}
360
359
361
-
Something's wrong with how the `Profile` component is declared and used. Can you spot the mistake? (Try to remember how React distinguishes components from the regular HTML tags!)
360
+
هناك خطأ في كيفية تعريف واستخدام المكوّن `Profile`. هل يمكنك اكتشاف الخطأ؟ (حاول تذكر كيف تمّيز React المكوّنات عن وسوم HTML!)
Write a component from scratch. You can give it any valid name and return any markup. If you're out of ideas, you can write a`Congratulations`component that shows `<h1>Good job!</h1>`. Don't forget to export it!
432
+
قم بكتابة مكوّن من الصفر. يمكنك إعطائه أي اسم صالح وإرجاع أي ترميز مرئي. إذا كنت بحاجة إلى أفكار، يمكنك كتابة مكوّن `Congratulations`الذي يعرض `<h1>عمل رائع!</h1>`. لا تنسى تصديره!
434
433
435
434
<Sandpack>
436
435
437
436
```js
438
-
//Write your component below!
437
+
//قم بكتابة مكونك بالأسفل
439
438
440
439
```
441
440
@@ -448,7 +447,7 @@ Write a component from scratch. You can give it any valid name and return any ma
0 commit comments