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/reference/react/useContext.md
+12-34Lines changed: 12 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -38,23 +38,13 @@ function MyComponent() {
38
38
39
39
#### রিটার্নস {/*returns*/}
40
40
41
-
<<<<<<< HEAD
42
-
যে কম্পোনেন্টে `useContext` কল করা হয় তার জন্য context এর ভ্যালু রিটার্ন করে। যে কম্পোনেন্ট কল করা হয়েছে তার উপরে কম্পোনেন্ট ট্রির সব থেকে কাছের `SomeContext.Provider` দ্বারা নির্ধারিত হয় যা `value` হিসাবে পাঠানো হয়। যদি এমন কোন provider না থাকে, তাহলে তার রিটার্ন করা মান হবে `defaultValue` যা আপনি context এর জন্য [`createContext`](/reference/react/createContext) এ পাঠিয়েছিলেন। রিটার্ন্ড মান সবসময় আপ টু ডেট হবে। যদি context এ কোন পরিবর্তন হয়, তাহলে context ব্যবহারকৃত কম্পোনেন্টগুলোকে React স্বয়ংক্রিয়ভাবে পুনরায় রেন্ডার করবে।
43
-
=======
44
-
`useContext` returns the context value for the calling component. It is determined as the `value` passed to the closest `SomeContext` above the calling component in the tree. If there is no such provider, then the returned value will be the `defaultValue` you have passed to [`createContext`](/reference/react/createContext) for that context. The returned value is always up-to-date. React automatically re-renders components that read some context if it changes.
45
-
>>>>>>> 50d6991ca6652f4bc4c985cf0c0e593864f2cc91
41
+
`useContext` যে কম্পোনেন্টে কল করা হয় তার জন্য context এর মান রিটার্ন করে। এটি কম্পোনেন্ট ট্রিতে কলিং কম্পোনেন্টের উপরে সবচেয়ে কাছের `SomeContext` এর কাছে পাঠানো `value` দ্বারা নির্ধারিত হয়। যদি এমন কোন provider না থাকে, তাহলে রিটার্ন করা মান হবে `defaultValue` যা আপনি সেই context এর জন্য [`createContext`](/reference/react/createContext) এ পাঠিয়েছিলেন। রিটার্ন করা মান সবসময় আপ-টু-ডেট থাকে। যদি context পরিবর্তিত হয়, তাহলে React স্বয়ংক্রিয়ভাবে সেই কম্পোনেন্টগুলোকে পুনরায় রেন্ডার করে যারা কোন context পড়ে।
46
42
47
43
#### সতর্কতা {/*caveats*/}
48
44
49
-
<<<<<<< HEAD
50
-
* একটি কম্পোনেন্টের ভিতর `useContext()` কল করা হলে সেই *একই* কম্পোনেন্ট থেকে রিটার্নড হওয়া providers দিয়ে এটি প্রভাবিত হবে না। যে কম্পোনেন্ট থেকে `useContext()` কল করা হয়েছে, সংশ্লিষ্ট `<Context.Provider>` কে সেই কম্পোনেন্টের ***উপরে* থাকতে হবে**
51
-
* provider এর শুরু থেকে যেসব চিলড্রেন একটি নির্দিষ্ট context ব্যবহার করে সেটি যখন ভিন্ন `মান` গ্রহণ করে তখন React সেসব চিলড্রেনকে **স্বয়ংক্রিয়ভাবে পুনরায় রেন্ডার** করে। আগের এবং পরের মান [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) এর মাধ্যমে তুলনা করা হয়। পুনরায় রেন্ডার এড়িয়ে যেতে যেসব চিলড্রেনে [`memo`](/reference/react/memo) ব্যবহার করা হয়, সেখানে context এর নতুন মান পেতে বাধা দেওয়া হয় না।
52
-
* যদি আপনার বিল্ড সিস্টেম আউটপুটে ডুপ্লিকেট মডিউল উৎপাদন করে (যা symlinks দ্বারা তৈরি হয়), তাহলে সেটা আপনার context কে ব্রেক করতে পারে। কোন কিছু যখন context এর মাধ্যমে পাঠানো হয়, সেটি শুধুমাত্র তখনই কাজ করবে যখন আপনার context প্রদান করার জন্য ব্যবহারকৃত `SomeContext` এবং রিড করার জন্য ব্যবহারকৃত `SomeContext` ***হুবহু* একই object** হবে, যা `===` এর মাধ্যমে তুলনা করে নির্ধারিত হয়।
53
-
=======
54
-
* `useContext()` call in a component is not affected by providers returned from the *same* component. The corresponding `<Context>` **needs to be *above*** the component doing the `useContext()` call.
55
-
* React **automatically re-renders** all the children that use a particular context starting from the provider that receives a different `value`. The previous and the next values are compared with the [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) comparison. Skipping re-renders with [`memo`](/reference/react/memo) does not prevent the children receiving fresh context values.
56
-
* If your build system produces duplicates modules in the output (which can happen with symlinks), this can break context. Passing something via context only works if `SomeContext` that you use to provide context and `SomeContext` that you use to read it are ***exactly* the same object**, as determined by a `===` comparison.
57
-
>>>>>>> 50d6991ca6652f4bc4c985cf0c0e593864f2cc91
45
+
* একটি কম্পোনেন্টের ভিতর `useContext()` কল করা হলে সেই *একই* কম্পোনেন্ট থেকে রিটার্ন করা provider দিয়ে এটি প্রভাবিত হয় না। যে কম্পোনেন্ট থেকে `useContext()` কল করা হয়েছে, সংশ্লিষ্ট `<Context>` কে সেই কম্পোনেন্টের ***উপরে* থাকতে হবে**।
46
+
* React **স্বয়ংক্রিয়ভাবে পুনরায় রেন্ডার** করে সেইসব চিলড্রেনকে যারা একটি নির্দিষ্ট context ব্যবহার করে, শুরু করে সেই provider থেকে যা ভিন্ন `value` পায়। আগের এবং পরের মান [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) এর মাধ্যমে তুলনা করা হয়। [`memo`](/reference/react/memo) দিয়ে পুনরায় রেন্ডার এড়ানো চিলড্রেনদের নতুন context এর মান পেতে বাধা দেয় না।
47
+
* যদি আপনার বিল্ড সিস্টেম আউটপুটে ডুপ্লিকেট মডিউল উৎপাদন করে (যা symlinks দ্বারা হতে পারে), তাহলে সেটা আপনার context কে ভাঙতে পারে। কোন কিছু context এর মাধ্যমে পাঠানো শুধুমাত্র তখনই কাজ করে যখন আপনার context প্রদান করার জন্য ব্যবহারকৃত `SomeContext` এবং রিড করার জন্য ব্যবহারকৃত `SomeContext` ***হুবহু* একই object** হয়, যা `===` তুলনা দ্বারা নির্ধারিত হয়।
58
48
59
49
---
60
50
@@ -829,7 +819,7 @@ function tasksReducer(tasks, action) {
829
819
}
830
820
831
821
constinitialTasks= [
832
-
{ id:0, text:'Philosopher’s Path', done:true },
822
+
{ id:0, text:'Philosopher's Path', done: true },
833
823
{ id: 1, text: 'Visit the temple', done: false },
834
824
{ id: 2, text: 'Drink matcha', done: false }
835
825
];
@@ -1355,23 +1345,17 @@ function MyApp() {
1355
1345
1356
1346
## সমস্যা সমাধান {/*troubleshooting*/}
1357
1347
1358
-
### আমার কম্পোনেন্ট আমার provider এর মান দেখতে পায় না {/*my-component-doesnt-see-the-value-from-my-provider*/}
1348
+
### আমার কম্পোনেন্ট আমার provider এর মান দেখতে পায় না {/*my-component-doesnt-see-the-value-from-my-provider*/}
1359
1349
1360
1350
কিছু সাধারণ কারণে এমনটি ঘটতে পারে:
1361
1351
1362
-
<<<<<<< HEAD
1363
-
1. আপনি যেখানে `useContext()` কল করছেন সেই কম্পোনেন্টে (অথবা নিচে) `<SomeContext.Provider>` রেন্ডার করেছেন। যে কম্পোনেন্টে `useContext()` কল হচ্ছে তার *উপরে এবং বাইরে* `<SomeContext.Provider>` কে সরিয়ে ফেলুন।
1364
-
2. আপনি হয়ত `<SomeContext.Provider>` দিয়ে আপনার কম্পোনেন্টকে wrap করতে ভুলে গেছেন, অথবা আপনি এটিকে ট্রির যেখানে রাখার কথা ভেবেছিলেন তার থেকে হয়ত ভিন্ন কোথাও রেখেছেন। [React DevTools](/learn/react-developer-tools) ব্যবহার করে hierarchy টি সঠিক কি না তা পরীক্ষা করুন।
1365
-
3. আপনি হয়ত আপনার টুলিং সম্পর্কিত কিছু বিল্ড সমস্যার ভিতর দিয়ে যাচ্ছেন যার ফলে প্রোভাইডিং কম্পোনেন্ট থেকে `SomeContext` এবং রিডিং কম্পোনেন্ট থেকে `SomeContext` ভিন্ন object হিসাবে দেখাচ্ছে। উদাহরণস্বরূপ, আপনি যদি symlink ব্যবহার করেন, আপনি এগুলোকে গ্লোবালে যুক্ত করে (যেমন `window.SomeContext1` এবং `window.SomeContext2`) এবং তারপর কনসোলে `window.SomeContext1 === window.SomeContext2` কি না তা পরীক্ষা করে এটি যাচাই করতে পারেন। যদি তারা একই না হয়, তাহলে বিল্ড টুল স্তরে সেই সমস্যাটি ঠিক করুন।
1366
-
=======
1367
-
1. You're rendering `<SomeContext>` in the same component (or below) as where you're calling `useContext()`. Move `<SomeContext>` *above and outside* the component calling `useContext()`.
1368
-
2. You may have forgotten to wrap your component with `<SomeContext>`, or you might have put it in a different part of the tree than you thought. Check whether the hierarchy is right using [React DevTools.](/learn/react-developer-tools)
1369
-
3. You might be running into some build issue with your tooling that causes `SomeContext` as seen from the providing component and `SomeContext` as seen by the reading component to be two different objects. This can happen if you use symlinks, for example. You can verify this by assigning them to globals like `window.SomeContext1` and `window.SomeContext2` and then checking whether `window.SomeContext1===window.SomeContext2` in the console. If they're not the same, fix that issue on the build tool level.
1370
-
>>>>>>> 50d6991ca6652f4bc4c985cf0c0e593864f2cc91
1352
+
1. আপনি যেখানে `useContext()` কল করছেন সেই কম্পোনেন্টে (অথবা নিচে) `<SomeContext>` রেন্ডার করেছেন। যে কম্পোনেন্টে `useContext()` কল হচ্ছে তার *উপরে এবং বাইরে* `<SomeContext>` কে সরিয়ে ফেলুন।
1353
+
2. আপনি হয়ত `<SomeContext>` দিয়ে আপনার কম্পোনেন্টকে wrap করতে ভুলে গেছেন, অথবা আপনি এটিকে ট্রির যেখানে রাখার কথা ভেবেছিলেন তার থেকে হয়ত ভিন্ন কোথাও রেখেছেন। [React DevTools](/learn/react-developer-tools) ব্যবহার করে hierarchy টি সঠিক কি না তা পরীক্ষা করুন।
1354
+
3. আপনি হয়ত আপনার টুলিং সম্পর্কিত কিছু বিল্ড সমস্যার মধ্যে পড়েছেন যার ফলে প্রোভাইডিং কম্পোনেন্ট থেকে `SomeContext` এবং রিডিং কম্পোনেন্ট থেকে `SomeContext` ভিন্ন object হিসাবে দেখাচ্ছে। উদাহরণস্বরূপ, আপনি যদি symlink ব্যবহার করেন, আপনি এগুলোকে গ্লোবালে যুক্ত করে (যেমন `window.SomeContext1` এবং `window.SomeContext2`) এবং তারপর কনসোলে `window.SomeContext1 === window.SomeContext2` কি না তা পরীক্ষা করে এটি যাচাই করতে পারেন। যদি তারা একই না হয়, তাহলে বিল্ড টুল স্তরে সেই সমস্যাটি ঠিক করুন।
1371
1355
1372
1356
### আমি সব সময় আমার context থেকে `undefined` পাচ্ছি যদিও ডিফল্ট মান ভিন্ন {/*i-am-always-getting-undefined-from-my-context-although-the-default-value-is-different*/}
1373
1357
1374
-
ট্রিতে হয়ত আপনার একটি `value` বিহীন provider আছেঃ
1358
+
ট্রিতে হয়ত আপনার একটি `value` বিহীন provider আছেঃ
1375
1359
1376
1360
```js {1,2}
1377
1361
// 🚩 Doesn't work: no value prop
@@ -1382,7 +1366,7 @@ function MyApp() {
1382
1366
1383
1367
আপনি যদি `value` উল্লেখ করতে ভুলে যান, তাহলে এটি `value={undefined}` এরকম কিছু পাস করে।
1384
1368
1385
-
আপনি হয়ত ভুল করে একটি ভিন্ন প্রপ নাম ব্যবহার করতে পারেন:
1369
+
আপনি হয়ত ভুল করে একটি ভিন্ন প্রপ নাম ব্যবহার করতে পারেন:
1386
1370
1387
1371
```js {1,2}
1388
1372
// 🚩 Doesn't work: prop should be called "value"
@@ -1391,17 +1375,11 @@ function MyApp() {
1391
1375
</ThemeContext>
1392
1376
```
1393
1377
1394
-
উভয় ক্ষেত্রেই আপনি কনসোলে React থেকে একটি ওয়ার্নিং দেখতে পাবেন। তাদের ঠিক করতে, প্রপ হিসাবে `value` কল করুন:
1378
+
উভয় ক্ষেত্রেই আপনি কনসোলে React থেকে একটি ওয়ার্নিং দেখতে পাবেন। তাদের ঠিক করতে, প্রপ হিসাবে `value` কল করুন:
1395
1379
1396
1380
```js {1,2}
1397
1381
// ✅ Passing the value prop
1398
1382
<ThemeContext value={theme}>
1399
1383
<Button />
1400
1384
</ThemeContext>
1401
1385
```
1402
-
1403
-
<<<<<<< HEAD
1404
-
মনে রাখবেন যে আপনার [`createContext(defaultValue)` কল থেকে ডিফল্ট মানটি](#specifying-a-fallback-default-value) শুধুমাত্র তখনই ব্যবহার করা হয় **যদি উপরে কোন provider এর সাথে মিল না পায়।** যদি প্যারেন্ট ট্রিতে কোথাও একটি `<SomeContext.Provider value={undefined}>` কম্পোনেন্ট থাকে, তাহলে যে কম্পোনেন্ট `useContext(SomeContext)` কল করছে সে context এর মান হিসাবে `undefined` পাবে।
1405
-
=======
1406
-
Note that the [default value from your `createContext(defaultValue)` call](#specifying-a-fallback-default-value) is only used **if there is no matching provider above at all.** If there is a `<SomeContext value={undefined}>` component somewhere in the parent tree, the component calling `useContext(SomeContext)` *will* receive `undefined` as the context value.
0 commit comments