Skip to content

Commit 29c856e

Browse files
authored
Merge pull request #391 from nafasebra/main
Translate 'importing and exporting components' to Farsi
2 parents c5daba7 + 62fdd8e commit 29c856e

File tree

1 file changed

+54
-54
lines changed

1 file changed

+54
-54
lines changed

src/content/learn/importing-and-exporting-components.md

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@ title: Importing and Exporting Components
44

55
<Intro>
66

7-
The magic of components lies in their reusability: you can create components that are composed of other components. But as you nest more and more components, it often makes sense to start splitting them into different files. This lets you keep your files easy to scan and reuse components in more places.
7+
کاربرد اصلی کامپوننت ها, قابلیت استفاده مجدد آنهاست: شما میتوانید کامپوننت هایی بسازید که متشکل از کامپوننت های دیگر هستند ولی درگل بهتر است که هربخشی را تبدیل به کامپوننت کنید چون اسکن کردن آنها توسط اجرا کننده آسان تر است.
88

99
</Intro>
1010

1111
<YouWillLearn>
1212

13-
* What a root component file is
14-
* How to import and export a component
15-
* When to use default and named imports and exports
16-
* How to import and export multiple components from one file
17-
* How to split components into multiple files
13+
* کامپوننت ریشه (root) چیست
14+
* چگونه کامپوننتی را ایمپورت یا اکسپورت (import - export) کنیم
15+
* از دستور default استفاده کنم
16+
* چگونه چندین کامپوننت که داخل یک فایل هستند را export کنم.
17+
* چگونه در چندین فایل کامپوننت هارا تقسیم کنم
1818

1919
</YouWillLearn>
2020

21-
## The root component file {/*the-root-component-file*/}
21+
## فایل کامپوننت اصلی {/*the-root-component-file*/}
2222

23-
In [Your First Component](/learn/your-first-component), you made a `Profile` component and a `Gallery` component that renders it:
23+
در بخش [Your First Component](/learn/your-first-component), شما یک `Profile` کامپوننت ساختید و یک کامپوننت `Gallery` داخل آن رندر میشود:
2424

2525
<Sandpack>
2626

@@ -52,17 +52,17 @@ img { margin: 0 10px 10px 0; height: 90px; }
5252

5353
</Sandpack>
5454

55-
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 متفاوت است
5656

57-
## Exporting and importing a component {/*exporting-and-importing-a-component*/}
57+
## ایمپورت و اکسپورت کردن کامپوننت ها {/*exporting-and-importing-a-component*/}
5858

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` داشته باشید. بهتر است داخل فایل کامپوننت اصلی نباشند و در کامپوننت های جداگانه ای قرار بدهید.
6060

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).
6464

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` تغییر دهید
6666

6767
<Sandpack>
6868

@@ -104,82 +104,82 @@ img { margin: 0 10px 10px 0; height: 90px; }
104104

105105
</Sandpack>
106106

107-
Notice how this example is broken down into two component files now:
107+
به موارد زیر که به دو کامپوننت تقسیم شدند دقت کنید:
108108

109109
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.** اکسپورت گرفته
112112
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.** اکسپورت کرده
115115

116116

117117
<Note>
118118

119-
You may encounter files that leave off the `.js` file extension like so:
119+
ممکن است با فایل هایی مواجه بشوید که پسوند `.js` را نداشته باشند:
120120

121121
```js
122122
import Gallery from './Gallery';
123123
```
124124

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) نزدیک تر است.
126126

127127
</Note>
128128

129129
<DeepDive>
130130

131-
#### Default vs named exports {/*default-vs-named-exports*/}
131+
#### دستور default و export {/*default-vs-named-exports*/}
132132

133-
There are two primary ways to export values with JavaScript: default exports and named exports. So far, our examples have only used default exports. But you can use one or both of them in the same file. **A file can have no more than one _default_ export, but it can have as many _named_ exports as you like.**
133+
در اینجا دو راه اصلی وجود دارد که کامپوننت ها یا توابع و یا متغیر هایمان را export کنیم: default export و export خالی. تا اینجا در مثال ها از default export استفاده شده اما از این به بعد شما میتوانید از دستور export خالی هم استفاده کنید.
134134

135135
![Default and named exports](/images/docs/illustrations/i_import-export.svg)
136136

137-
How you export your component dictates how you must import it. You will get an error if you try to import a default export the same way you would a named export! This chart can help you keep track:
137+
اینکه چطور کامپوننت را ایمپورت کنید بستگی دارد به اینکه چطور آن را اکسپورت کنید. و اگر در جای خود استفاده نکنید به ارور برمیخورید.
138138

139139
| Syntax | Export statement | Import statement |
140140
| ----------- | ----------- | ----------- |
141141
| Default | `export default function Button() {}` | `import Button from './Button.js';` |
142142
| Named | `export function Button() {}` | `import { Button } from './Button.js';` |
143143

144-
When you write a _default_ import, you can put any name you want after `import`. For example, you could write `import Banana from './Button.js'` instead and it would still provide you with the same default export. In contrast, with named imports, the name has to match on both sides. That's why they are called _named_ imports!
144+
زمانی که شما به صورت پیش فرض ایمپورت میکنید (default import), شما میتوانید هر اسمی را بعد از import به عنوان نام متغیر بنویسید, حتی میتوانید مثلا بنویسید `import Banana from './Button.js'` ولی در ایمپورت هایی دیگر باید اسمی که در همان فایل اکسپورت کردید را بنویسید.
145145

146-
**People often use default exports if the file exports only one component, and use named exports if it exports multiple components and values.** Regardless of which coding style you prefer, always give meaningful names to your component functions and the files that contain them. Components without names, like `export default () => {}`, are discouraged because they make debugging harder.
146+
**معمولا از ایمپورت پیش فرض استفاده میشود, مخصوصا زمانی که یک کامپوننت یا تابع داخل یک فایل داریم. و زمانی که از ایمپورت معمولی (named import) که در یک فایل چندین تابع یا کامپوننت داشته باشیم** صرف نظر از اینکه از کدام روش استفاده میکنید, سعی کنید نام های مناسبی برای توابع و کامپوننت ها و ایمپورت ها انتخاب کنید. دستوری مانند `export default () => {}` مشکل زا هست و حذف میشود.
147147

148148
</DeepDive>
149149

150-
## Exporting and importing multiple components from the same file {/*exporting-and-importing-multiple-components-from-the-same-file*/}
150+
## اکسپورت و ایمپورت کردن چند کامپوننت از یک فایل {/*exporting-and-importing-multiple-components-from-the-same-file*/}
151151

152-
What if you want to show just one `Profile` instead of a gallery? You can export the `Profile` component, too. But `Gallery.js` already has a *default* export, and you can't have _two_ default exports. You could create a new file with a default export, or you could add a *named* export for `Profile`. **A file can only have one default export, but it can have numerous named exports!**
152+
برگردیم به مثال قبلی, فرض کنیم دو کامپوننت `Profile` و `Gallery` را داخل یک فایل داشته باشیم. نمیتوانیم به صورت پیش فرض از آنها اکسپورت بگیریم (export default). پس چکار کنیم؟ از اکسپورت معمولی (export) استفاده میکنیم. **در یک فایل فقط یک export default داشته باشد ولی به تعداد مدنظر میتوانید اکسپورت معمولی داشته باشید**
153153

154154
<Note>
155155

156-
To reduce the potential confusion between default and named exports, some teams choose to only stick to one style (default or named), or avoid mixing them in a single file. Do what works best for you!
156+
شاید پیش خود سوال کنید که از کدام استفاده کنم؟ یکسری از تیم ها فقط از export default استفاده کنند و مابقی توابع داخل فایل را با آن ادغام کنند. یا از export سراسر فایل استفاده کنند. اینکه کدام بهتر است به خودتان بستگی دارد.
157157

158158
</Note>
159159

160-
First, **export** `Profile` from `Gallery.js` using a named export (no `default` keyword):
160+
ابتدا, کامپوننت `Profile` را که در فایل `Gallery.js` موجود است را به اکسپورت بگیرید (از کلمه کلیدی `default` استفاده نکنید):
161161

162162
```js
163163
export function Profile() {
164164
// ...
165165
}
166166
```
167167

168-
Then, **import** `Profile` from `Gallery.js` to `App.js` using a named import (with the curly braces):
168+
سپس, کامپوننت `Profile` را از فایل `Gallery.js` به فایل `App.js` ایمپورت کنید (از علامت آکولاد استفاده کنید):
169169

170170
```js
171171
import { Profile } from './Gallery.js';
172172
```
173173

174-
Finally, **render** `<Profile />` from the `App` component:
174+
و در آخر, کامپوننت `<Profile />` در کامپوننت `App` رندر میشود:
175175

176176
```js
177177
export default function App() {
178178
return <Profile />;
179179
}
180180
```
181181

182-
Now `Gallery.js` contains two exports: a default `Gallery` export, and a named `Profile` export. `App.js` imports both of them. Try editing `<Profile />` to `<Gallery />` and back in this example:
182+
حال در اینجا فایل `Gallery.js` دو export دارد: یک default export مربوط به کامپوننت `Gallery`, و یک named export مربوط به کامپوننت `Profile`. در فایل `App.js` هردوی آنها ایمپورت میشوند. حال دستور `<Profile />` را به `<Gallery />` تغییر بدهید و به مثال بازگردید:
183183

184184
<Sandpack>
185185

@@ -222,38 +222,38 @@ img { margin: 0 10px 10px 0; height: 90px; }
222222

223223
</Sandpack>
224224

225-
Now you're using a mix of default and named exports:
225+
حال شما از هر دو نوع از دستور export استفاده کردید:
226226

227227
* `Gallery.js`:
228-
- Exports the `Profile` component as a **named export called `Profile`.**
229-
- Exports the `Gallery` component as a **default export.**
228+
- کامپوننت `Profile` به عنوان **named export** که نام آن `Profile` است اکسپورت شده.
229+
- کامپوننت `Gallery` به عنوان **default export** اکسپورت شده است
230230
* `App.js`:
231-
- Imports `Profile` as a **named import called `Profile`** from `Gallery.js`.
232-
- Imports `Gallery` as a **default import** from `Gallery.js`.
233-
- Exports the root `App` component as a **default export.**
231+
- کامپوننت `Profile` به عنوان **named import** که نام آن `Profile` است در `Gallery.js` ایمپورت شده.
232+
- کامپوننت `Gallery` به عنوان **default import** در فایل `Gallery.js` ایمپورت شده.
233+
- کامپوننت `App` که کامپوننت ریشه است به عنوان **default export** اکسپورت شده است.
234234

235235
<Recap>
236236

237-
On this page you learned:
237+
مواردی که در این صفحه یاد گرفتید:
238238

239-
* What a root component file is
240-
* How to import and export a component
241-
* When and how to use default and named imports and exports
242-
* How to export multiple components from the same file
239+
* کامپوننت اصلی (root) چیست
240+
* چگونه یک کامپوننت را export/import کنیم
241+
* چه زمانی از export/import پیش فرض یا معمولی استفاده کنیم
242+
* چگونه چندین کامپوننت را که داخل یک فایل هستند را اکسپورت کنیم
243243

244244
</Recap>
245245

246246

247247

248248
<Challenges>
249249

250-
#### Split the components further {/*split-the-components-further*/}
250+
#### تا جایی که میتوانید کامپوننت هارا به کامپوننت های کوچک تری تقسیم کنید {/*split-the-components-further*/}
251251

252-
Currently, `Gallery.js` exports both `Profile` and `Gallery`, which is a bit confusing.
252+
در حال حاضر, فایل `Gallery.js` دو کامپوننت `Profile` و `Gallery` را اکسپورت میکند, که یک مقداری گیج کنندست.
253253

254-
Move the `Profile` component to its own `Profile.js`, and then change the `App` component to render both `<Profile />` and `<Gallery />` one after another.
254+
یک فایلی را با نام `Profile.js` بسازید و کامپوننت `Profile` را درون آن بیاورید و اکسپورت کنید. سپس در کامپوننت `App` همان را ایمپورت کنید.
255255

256-
You may use either a default or a named export for `Profile`, but make sure that you use the corresponding import syntax in both `App.js` and `Gallery.js`! You can refer to the table from the deep dive above:
256+
هنگام استفاده از دستور export و import مطمئن شوید از کدام روش استفاده میکنید. برای این منظور جدول زیر را چک کنید:
257257

258258
| Syntax | Export statement | Import statement |
259259
| ----------- | ----------- | ----------- |
@@ -262,7 +262,7 @@ You may use either a default or a named export for `Profile`, but make sure that
262262

263263
<Hint>
264264

265-
Don't forget to import your components where they are called. Doesn't `Gallery` use `Profile`, too?
265+
زمانی که کامپوننت هارا صدا میزنید, حتما کامپوننت هارا import کنید. به نظر شما تا اینجا ما کامپوننت `Profile` را هم در فایل `Gallery.js` داریم؟
266266

267267
</Hint>
268268

@@ -282,7 +282,7 @@ export default function App() {
282282
```
283283

284284
```js Gallery.js active
285-
// Move me to Profile.js!
285+
// Profile.js منو بیار توی فایل
286286
export function Profile() {
287287
return (
288288
<img
@@ -313,11 +313,11 @@ img { margin: 0 10px 10px 0; height: 90px; }
313313

314314
</Sandpack>
315315

316-
After you get it working with one kind of exports, make it work with the other kind.
316+
خب بسیار هم عالی! الان وقت آن رسیده که با نوع دیگری از export کار کنید.
317317

318318
<Solution>
319319

320-
This is the solution with named exports:
320+
این تکه کد از named export (دستور اکسپورت معمولی) استفاده کرده است:
321321

322322
<Sandpack>
323323

@@ -367,7 +367,7 @@ img { margin: 0 10px 10px 0; height: 90px; }
367367

368368
</Sandpack>
369369

370-
This is the solution with default exports:
370+
و همچنین کد زیر هم با default export (اکسپورت پیش فرض) نوشته شده است:
371371

372372
<Sandpack>
373373

0 commit comments

Comments
 (0)