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/keeping-components-pure.md
+30-30Lines changed: 30 additions & 30 deletions
Original file line number
Diff line number
Diff line change
@@ -1,51 +1,51 @@
1
1
---
2
-
title: Keeping Components Pure
2
+
title: কম্পোনেন্টকে বিশুদ্ধ রাখা
3
3
---
4
4
5
5
<Intro>
6
6
7
-
Some JavaScript functions are *pure.* Pure functions only perform a calculation and nothing more. By strictly only writing your components as pure functions, you can avoid an entire class of baffling bugs and unpredictable behavior as your codebase grows. To get these benefits, though, there are a few rules you must follow.
7
+
কিছু জাভাস্ক্রিপ্ট ফাংশন *বিশুদ্ধ।* বিশুদ্ধ ফাংশনগুলো শুধুমাত্র একটি হিসাব করে, অন্য কিছু নয়। আপনি যথাযথভাবে আপনার কম্পোনেন্টগুলোকে বিশুদ্ধ ফাংশন হিসাবে লিখার মাধ্যমে আপনার কোডবেইজ বাড়ার সাথে সাথে অনেক বিভ্রান্তিকর বাগ এবং অনিশ্চিত আচরণ এড়িয়ে যেতে পারবেন। এই সুবিধাগুলো পাওয়ার জন্য আপনার নির্দিষ্ট কিছু নিয়ম মেনে চলতে হবে।
8
8
9
9
</Intro>
10
10
11
11
<YouWillLearn>
12
12
13
-
*What purity is and how it helps you avoid bugs
14
-
*How to keep components pure by keeping changes out of the render phase
15
-
*How to use Strict Mode to find mistakes in your components
13
+
*বিশুদ্ধতা কি এবং এটি কিভাবে আপনাকে বাগ এড়িয়ে যেতে সাহায্য করে
14
+
*কম্পোনেন্টকে কিভাবে বিশুদ্ধ রাখা যায় পরিবর্তনগুলোকে রেন্ডারের ধাপের বাইরে রেখে
15
+
*কিভাবে Strict Mode ব্যবহার করে আপনার কম্পোনেন্টের ভুলগুলো ধরতে পারবেন
16
16
17
17
</YouWillLearn>
18
18
19
-
## Purity: Components as formulas {/*purity-components-as-formulas*/}
19
+
## বিশুদ্ধতাঃ সূত্র হিসেবে কম্পোনেন্ট {/*purity-components-as-formulas*/}
20
20
21
-
In computer science (and especially the world of functional programming), [a pure function](https://wikipedia.org/wiki/Pure_function)is a function with the following characteristics:
21
+
কম্পিউটার সায়েন্সে (বিশেষ করে ফাংশনাল প্রোগ্রামিং-এ), [একটি বিশুদ্ধ ফাংশন](https://wikipedia.org/wiki/Pure_function)হল এমন একটি ফাংশন যার নিচের বৈশিষ্ট্যগুলো রয়েছেঃ
22
22
23
-
***It minds its own business.**It does not change any objects or variables that existed before it was called.
24
-
***Same inputs, same output.**Given the same inputs, a pure function should always return the same result.
23
+
***নিজের কাজ নিয়েই ব্যস্ত।**এটি কল করার আগের কোন অবজেক্ট বা ভ্যারিয়েবল পরিবর্তন করেনা।
24
+
***একই ইনপুট, একই আউটপুট।**একই ইনপুটের জন্য একটি বিশুদ্ধ ফাংশন সবসময় একই আউটপুট রিটার্ন করে।
25
25
26
-
You might already be familiar with one example of pure functions: formulas in math.
26
+
আপনি হয়তো এরই মধ্যে বিশুদ্ধ ফাংশনের একটি উদাহরণের সাথে পরিচিতঃ গণিতের সূত্র।
27
27
28
-
Consider this math formula: <Math><MathI>y</MathI> = 2<MathI>x</MathI></Math>.
28
+
এই গণিতের সূত্রটিই ধরুনঃ <Math><MathI>y</MathI> = 2<MathI>x</MathI></Math>.
29
29
30
-
If <Math><MathI>x</MathI> = 2</Math> then <Math><MathI>y</MathI> = 4</Math>. Always.
30
+
যদি <Math><MathI>x</MathI> = 2</Math> হয়, তাহলে <Math><MathI>y</MathI> = 4</Math> হবে। সবসময়।
31
31
32
-
If <Math><MathI>x</MathI> = 3</Math> then <Math><MathI>y</MathI> = 6</Math>. Always.
32
+
যদি <Math><MathI>x</MathI> = 3</Math> হয়, তাহলে <Math><MathI>y</MathI> = 6</Math> হবে। সবসময়।
33
33
34
-
If <Math><MathI>x</MathI> = 3</Math>, <MathI>y</MathI> won't sometimes be <Math>9</Math> or <Math>–1</Math> or <Math>2.5</Math> depending on the time of day or the state of the stock market.
34
+
যদি <Math><MathI>x</MathI> = 3</Math> হয়, তাহলে <MathI>y</MathI> কখনো কখনো <Math>9</Math> অথবা <Math>–1</Math> অথবা <Math>2.5</Math> হবেনা, দিনের কোন সময় বা স্টক মার্কেটের অবস্থার উপর নির্ভর করে।
35
35
36
-
If <Math><MathI>y</MathI> = 2<MathI>x</MathI></Math> and <Math><MathI>x</MathI> = 3</Math>, <MathI>y</MathI> will _always_ be <Math>6</Math>.
36
+
যদি <Math><MathI>y</MathI> = 2<MathI>x</MathI></Math> এবং <Math><MathI>x</MathI> = 3</Math> হয়, <MathI>y</MathI> তাহলে _সবসময়_<Math>6</Math> হবে।
37
37
38
-
If we made this into a JavaScript function, it would look like this:
38
+
আমরা যদি এটিকে একটি জাভাস্ক্রিপ্ট ফাংশনে রুপ দেই, তাহলে এটি এমন দেখাবেঃ
39
39
40
40
```js
41
41
functiondouble(number) {
42
42
return2* number;
43
43
}
44
44
```
45
45
46
-
In the above example, `double`is a **pure function.**If you pass it `3`, it will return`6`. Always.
46
+
উপরের উদাহরণে, `double`একটি **বিশুদ্ধ ফাংশন।**আপনি যদি এটিতে `3` পাস করেন এটি`6` রিটার্ন করবে। সবসময়।
47
47
48
-
React is designed around this concept. **React assumes that every component you write is a pure function.**This means that React components you write must always return the same JSX given the same inputs:
48
+
React এই ধারণার উপর ভিত্তি করেই তৈরি করা হয়েছে। **React ধরে নেয় আপনার লেখা সব কম্পোনেন্টই বিশুদ্ধ ফাংশন।**তার মানে আপনার লিখা React কম্পোনেন্টগুলোর অবশ্যই একই ইনপুটের জন্য একই JSX রিটার্ন করতে হবেঃ
49
49
50
50
<Sandpack>
51
51
@@ -75,21 +75,21 @@ export default function App() {
75
75
76
76
</Sandpack>
77
77
78
-
When you pass `drinkers={2}`to `Recipe`, it will return JSX containing`2 cups of water`. Always.
78
+
আপনি যখন `Recipe` তে `drinkers={2}`পাস করবেন, এটি JSX রিটার্ন করবে যাতে`2 cups of water` থাকবে। সবসময়।
79
79
80
-
If you pass `drinkers={4}`, it will return JSX containing `4 cups of water`. Always.
80
+
যদি আপনি `drinkers={4}` পাস করেন, এটি JSX রিটার্ন করবে যাতে `4 cups of water` থাকবে। সবসময়।
81
81
82
-
Just like a math formula.
82
+
ঠিক একটি গণিতের সূত্রের মত।
83
83
84
-
You could think of your components as recipes: if you follow them and don't introduce new ingredients during the cooking process, you will get the same dish every time. That "dish" is the JSX that the component serves to React to [render.](/learn/render-and-commit)
84
+
আপনি আপনার কম্পোনেন্টকে একটি রেসিপি হিসেবে চিন্তা করতে পারেনঃ যদি আপনি এগুলো অনুসরণ করেন এবং রান্নার সময়ে নতুন কোন উপাদান না আনেন তাহলে আপনি সবসময় একই খাবার পাবেন। এই "খাবার" হল JSX যা আপনার কম্পোনেন্ট React কে [রেন্ডার](/learn/render-and-commit) করার জন্য পরিবেশন করে।
85
85
86
86
<Illustrationsrc="/images/docs/illustrations/i_puritea-recipe.png"alt="A tea recipe for x people: take x cups of water, add x spoons of tea and 0.5x spoons of spices, and 0.5x cups of milk" />
87
87
88
-
## Side Effects: (un)intended consequences {/*side-effects-unintended-consequences*/}
88
+
## পার্শ্ব-প্রতিক্রিয়াঃ (অন)ইচ্ছাকৃত প্রভাব {/*side-effects-unintended-consequences*/}
89
89
90
-
React's rendering process must always be pure. Components should only *return* their JSX, and not *change* any objects or variables that existed before rendering—that would make them impure!
90
+
React এর রেন্ডারিং প্রসেস সবসময় বিশুদ্ধ হতে হবে। কম্পোনেন্টগুলোর শুধুমাত্র তাদের JSX *রিটার্ন* করা উচিত, এবং রেন্ডারিং এর আগের কোন অবজেক্ট বা ভ্যারিয়েবলে পরিবর্তন আনা উচিত নয়-যা এগুলোকে অবিশুদ্ধ করে দেবে!
91
91
92
-
Here is a component that breaks this rule:
92
+
এই কম্পোনেন্টটি এই নিয়ম ভঙ্গ করেঃ
93
93
94
94
<Sandpack>
95
95
@@ -115,11 +115,11 @@ export default function TeaSet() {
115
115
116
116
</Sandpack>
117
117
118
-
This component is reading and writing a `guest`variable declared outside of it. This means that **calling this component multiple times will produce different JSX!**And what's more, if _other_ components read `guest`, they will produce different JSX, too, depending on when they were rendered! That's not predictable.
118
+
এই কম্পোনেন্টটি এর বাইরে ডিক্লেয়ার করা `guest`ভ্যারিয়েবল রিড এবং রাইট করছে। তার মানে **এই কম্পোনেন্ট বারবার কল করলে ভিন্ন ভিন্ন JSX রিটার্ন করবে!**তার উপর, যদি _অন্য_ কম্পোনেন্ট `guest` থেকে রিড করে, তারাও ভিন্ন JSX রিটার্ন করবে, তারা কখন রেন্ডার হয়েছিল এর উপর ভিত্তি করে! এটি মোটেও অনুমানযোগ্য নয়।
119
119
120
-
Going back to our formula <Math><MathI>y</MathI> = 2<MathI>x</MathI></Math>, now even if <Math><MathI>x</MathI> = 2</Math>, we cannot trust that <Math><MathI>y</MathI> = 4</Math>. Our tests could fail, our users would be baffled, planes would fall out of the sky—you can see how this would lead to confusing bugs!
120
+
আমরা যদি আমাদের সূত্রে ফিরে যাই, <Math><MathI>y</MathI> = 2<MathI>x</MathI></Math>, এখন <Math><MathI>x</MathI> = 2</Math> হওয়ার পরেও, আমরা নিশ্চিত হতে পারবনা <Math><MathI>y</MathI> = 4</Math> হবে। আমাদের টেস্ট ফেইল করতে পারে, আমাদের ইউজার বিস্মিত হতে পারে, প্লেইন আকাশ থেকে পড়ে যেতে পারে-দেখতেই পাচ্ছেন এটি কিভাবে বিভিন্ন বিভ্রান্তিকর বাগ তৈরি করতে পারে!
121
121
122
-
You can fix this component by [passing `guest`as a prop instead](/learn/passing-props-to-a-component):
122
+
আপনি এই কম্পোনেন্টে [`guest`একটি prop হিসেবে পাস করার মাধ্যমে](/learn/passing-props-to-a-component) এটি ঠিক করতে পারেনঃ
123
123
124
124
<Sandpack>
125
125
@@ -141,9 +141,9 @@ export default function TeaSet() {
141
141
142
142
</Sandpack>
143
143
144
-
Now your component is pure, as the JSX it returns only depends on the `guest` prop.
144
+
এখন আপনার কম্পোনেন্টটি বিশুদ্ধ, যেহেতু এর দ্বারা রিটার্নকৃত JSX শুধুমাত্র `guest` prop এর উপর নির্ভর করে।
145
145
146
-
In general, you should not expect your components to be rendered in any particular order. It doesn't matter if you call <Math><MathI>y</MathI> = 2<MathI>x</MathI></Math> before or after <Math><MathI>y</MathI> = 5<MathI>x</MathI></Math>: both formulas will resolve independently of each other. In the same way, each component should only "think for itself", and not attempt to coordinate with or depend upon others during rendering. Rendering is like a school exam: each component should calculate JSX on their own!
146
+
সাধারণত, আপনার কম্পোনেন্টকে নির্দিষ্ট কোন ক্রমে রেন্ডার করতে হবে এমন আশা করা উচিত নয়। এটি কোন ব্যাপার না আপনি <Math><MathI>y</MathI> = 2<MathI>x</MathI></Math> এর আগে অথবা পরে <Math><MathI>y</MathI> = 5<MathI>x</MathI></Math> কল করলেনঃ উভয় সূত্রই স্বাধীনভাবে সমাধান হবে। একইভাবে, প্রতিটা ক্মপোনেন্টেরই "নিজের জন্য চিন্তা করা" উচিত, এবং রেন্ডারিং এর সময় অন্যের সাথে সমন্বয়ের চেষ্টা অথবা অন্যের উপর নির্ভর করা উচিত নয়। রেন্ডারিং হল স্কুলের পরীক্ষার মতঃ প্রতিটা কম্পোনেন্টেরই তাদের নিজেদের JSX হিসাব করা উচিত!
0 commit comments