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
These currently live in a **root component file,** named `App.js`in this example. Depending on your setup, your root component could be in another file, though. If you use a framework with file-based routing, such as Next.js, your root component will be different for every page.
55
+
در این مثال, کامپوننت ریشه فایل `App.js`است. ممکن است این فایل در پروژه های مختلفی مانند NextJS متفاوت است
56
56
57
-
## Exporting and importing a component {/*exporting-and-importing-a-component*/}
57
+
## ایمپورت و اکسپورت کردن کامپوننت ها {/*exporting-and-importing-a-component*/}
58
58
59
-
What if you want to change the landing screen in the future and put a list of science books there? Or place all the profiles somewhere else? It makes sense to move `Gallery`and`Profile`out of the root component file. This will make them more modular and reusable in other files. You can move a component in three steps:
59
+
به عنوان مثال فرض کنید در یک لیست چند کامپوننت `Gallery`یا`Profile`داشته باشید. بهتر است داخل فایل کامپوننت اصلی نباشند و در کامپوننت های جداگانه ای قرار بدهید.
60
60
61
-
1.**Make**a new JS file to put the components in.
62
-
2.**Export** your function component from that file (using either[default](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/export#using_the_default_export)or [named](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/export#using_named_exports)exports).
63
-
3.**Import** it in the file where you’ll use the component (using the corresponding technique for importing [default](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/import#importing_defaults)or[named](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/import#import_a_single_export_from_a_module) exports).
61
+
1.یک فایل جاوااسکریپتی **بسازید**و تبدیل به یک کامپوننت کنید
62
+
2.در آن فایل, کامپوننت های خود را اکسپورت کنید (از [default](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/export#using_the_default_export)یا [name export](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/export#using_named_exports)کنید).
63
+
3.همان کامپوننت را در هر فایلی که میخواهید از آن استفاده کنید ایمپورت کنید (استفاده از تکنیک ایمپورت [default](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/import#importing_defaults)یا[named](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/import#import_a_single_export_from_a_module) exports).
64
64
65
-
Here both `Profile`and`Gallery`have been moved out of `App.js`into a new file called `Gallery.js`. Now you can change `App.js` to import `Gallery`from `Gallery.js`:
65
+
خب, اینجا کامپوننت های `Profile`و`Gallery`را ساخته ایم و داخل فایل `App.js`ایمپورت کردیم و داریم از آنها استفاده کنیم. حال در دستور ایمپورت مربوط به کامپوننت `Gallery`, بجای `Gallery`نام آن را به `Gallery.js` تغییر دهید
Notice how this example is broken down into two component files now:
107
+
به موارد زیر که به دو کامپوننت تقسیم شدند دقت کنید:
108
108
109
109
1.`Gallery.js`:
110
-
-Defines the `Profile`component which is only used within the same file and is not exported.
111
-
-Exports the`Gallery`component as a **default export.**
110
+
-کامپوننت `Profile`را صرفا تعریف کرده و آن را اکسپورت نکرده
111
+
-از کامپوننت`Gallery`به عنوان **default export.** اکسپورت گرفته
112
112
2.`App.js`:
113
-
-Imports`Gallery`as a **default import**from`Gallery.js`.
114
-
-Exports the root`App`component as a**default export.**
113
+
-کامپوننت`Gallery`را به عنوان **default import**از`Gallery.js` ایمپورت کرده
114
+
-کامپوننت اصلی یا`App`را به عنوان**default export.** اکسپورت کرده
115
115
116
116
117
117
<Note>
118
118
119
-
You may encounter files that leave off the `.js`file extension like so:
119
+
ممکن است با فایل هایی مواجه بشوید که پسوند `.js`را نداشته باشند:
120
120
121
121
```js
122
122
importGalleryfrom'./Gallery';
123
123
```
124
124
125
-
Either `'./Gallery.js'`or`'./Gallery'`will work with React, though the former is closer to how [native ES Modules](https://developer.mozilla.org/docs/Web/JavaScript/Guide/Modules)work.
125
+
دو آدرس `'./Gallery.js'`یا`'./Gallery'`داخل ریکت کار میکنند, اگر چه مورد اول به سازوکار [native ES Modules](https://developer.mozilla.org/docs/Web/JavaScript/Guide/Modules)نزدیک تر است.
0 commit comments