Skip to content

Commit eccade0

Browse files
committed
finished through Step4
1 parent a66be9b commit eccade0

1 file changed

Lines changed: 23 additions & 21 deletions

File tree

src/content/learn/thinking-in-react.md

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -248,40 +248,41 @@ td {
248248

249249
</DeepDive>
250250

251-
## Step 4: Identify where your state should live {/*step-4-identify-where-your-state-should-live*/}
251+
## الخطوة 4: حدد أين تضع الحالات {/*step-4-identify-where-your-state-should-live*/}
252252

253-
After identifying your app’s minimal state data, you need to identify which component is responsible for changing this state, or *owns* the state. Remember: React uses one-way data flow, passing data down the component hierarchy from parent to child component. It may not be immediately clear which component should own what state. This can be challenging if you’re new to this concept, but you can figure it out by following these steps!
253+
بعد أن حدد القدر الأدنى من بيانات الحالات اللازمة، عليك الأن أن تحدد أي المكونات مسءول عن تغيير كلٌّ من هذه الحالات، أو *يملك* تلك الحالة. تذكر أن React يستخدم سيل البيانات في اتجاه واحد، وهو تمرير البيانات من المكون الأب لمكون تابع له في التسلسل الشجري. قد لا يبدو واضحا من الوهلة الأولى أي مكون يجب أن يملك تلك "الحالة" ويكون مسؤولا عنها. ربما يكون هذا تحديا لك إن كان هذا المفهوم جديدا عليك،لكن ستتمكن من إيجاد الإجابة باتباع الخطوات التالية!
254254

255-
For each piece of state in your application:
255+
لكل حالة على حدة في تطبيقك:
256256

257-
1. Identify *every* component that renders something based on that state.
258-
2. Find their closest common parent component--a component above them all in the hierarchy.
259-
3. Decide where the state should live:
260-
1. Often, you can put the state directly into their common parent.
261-
2. You can also put the state into some component above their common parent.
262-
3. If you can't find a component where it makes sense to own the state, create a new component solely for holding the state and add it somewhere in the hierarchy above the common parent component.
257+
1. حدد *جميع* المكونات التي تعرض أي شيء له علاقة بهذه الحالة.
258+
2. حدد السلف الأقرب المشترك بينهم؛ مكون يكون أعلى منهم جميعا في التسلسل الشجري.
259+
3. حدد أين يجب أن تتمركز الحالة:
260+
1. عادة، يمكنك وضع الحالة مباشرة في سلفهم المشترك.
261+
2. يمكنك أيضا أن تضع الحالة في مكون أعلى من السلف المشترك.
262+
3. إن لم يكن بإمكانك تحديد مكون حيث يبدو من المنطقي وضع الحالة فيه، قم بعمل مكون جديد خصيصا لحفظ تلك الحالة، وقم بوضعه في مكان ما في التسلسل الشجري يسبق سلفهم المشترك.
263263

264-
In the previous step, you found two pieces of state in this application: the search input text, and the value of the checkbox. In this example, they always appear together, so it makes sense to put them into the same place.
264+
في الخطوة السابقة، وجدت حالتين في هذا التطبيق: نص البحث المكتوب، وحالة مربع الاختيار. في هذا المثال، يظهران دائما معا، فمن المنطقي وضعهم معا في نفس المكان.
265265

266266
Now let's run through our strategy for them:
267+
حسنا، لنقوم باختبار طريقتنا عليهم:
267268

268-
1. **Identify components that use state:**
269-
* `ProductTable` needs to filter the product list based on that state (search text and checkbox value).
270-
* `SearchBar` needs to display that state (search text and checkbox value).
271-
1. **Find their common parent:** The first parent component both components share is `FilterableProductTable`.
272-
2. **Decide where the state lives**: We'll keep the filter text and checked state values in `FilterableProductTable`.
269+
1. **حدد المكونات التي تستخدم الحالة:**
270+
* مكون (جدول المنتجات) `ProductTable` يحتاج الحالة ليقوم بتصفية قائمة المنتجات (نص البحث وحالة مربع الاختيار).
271+
* مكون (خانة البحث) `SearchBar` يقوم بعرض الحالة نفسها (نص البحث).
272+
1. **حدد لهم سلفا مشتركا:** السلف المشترك للمكونين هو `FilterableProductTable`.
273+
2. **حدد أين تضع الحالة**: سنضع نص البحث وحالة مربع الاختيار في المكون `FilterableProductTable`.
273274

274-
So the state values will live in `FilterableProductTable`.
275+
إذا، فقيم الحالات ستكون محفوظة لدى المكون `FilterableProductTable`.
275276

276-
Add state to the component with the [`useState()` Hook.](/reference/react/useState) Hooks are special functions that let you "hook into" React. Add two state variables at the top of `FilterableProductTable` and specify their initial state:
277+
أضف الحالات للمكون باستخدام [خطاف `useState()`.](/reference/react/useState) الخطافات (Hooks) عبارة عن دوال خاصة تسمح لك أن "تربط" مكوناتك بنظام React. أضف متغيرا لكل حالة في بداية الكود الخاص بالمكون `FilterableProductTable` وحدد حالتهم الأولية:
277278

278279
```js
279280
function FilterableProductTable({ products }) {
280281
const [filterText, setFilterText] = useState('');
281282
const [inStockOnly, setInStockOnly] = useState(false);
282283
```
283284
284-
Then, pass `filterText` and `inStockOnly` to `ProductTable` and `SearchBar` as props:
285+
ثم مرر المتغير `filterText` و `inStockOnly` للمكونين `ProductTable` و `SearchBar` كخاصية ضمن خصائص كلا منهما:
285286
286287
```js
287288
<div>
@@ -296,6 +297,7 @@ Then, pass `filterText` and `inStockOnly` to `ProductTable` and `SearchBar` as p
296297
```
297298
298299
You can start seeing how your application will behave. Edit the `filterText` initial value from `useState('')` to `useState('fruit')` in the sandbox code below. You'll see both the search input text and the table update:
300+
قد يبدو واضحا لك من الآن كيف سيبدو سلوك تطبيقك. قم بتعديل قيمة `filterText` الأولية من `useState('')` إلى `useState('fruit')` في الكود التالي داخل الـsandbox المدرج. سترى نتيجة التعديل على كلا من محتوى خانة البحث وجدول المنتجات:
299301
300302
<Sandpack>
301303
@@ -437,15 +439,15 @@ td {
437439
438440
</Sandpack>
439441
440-
Notice that editing the form doesn't work yet. There is a console error in the sandbox above explaining why:
442+
لاحظ أنك لو عدلت مباشرة على نموذج البحث فلن يحدث شيء. هناك رسالة خطأ في الـsandbox أعلاه تخبرك لماذا:
441443
442444
<ConsoleBlock level="error">
443445
444446
You provided a \`value\` prop to a form field without an \`onChange\` handler. This will render a read-only field.
445447
446448
</ConsoleBlock>
447449
448-
In the sandbox above, `ProductTable` and `SearchBar` read the `filterText` and `inStockOnly` props to render the table, the input, and the checkbox. For example, here is how `SearchBar` populates the input value:
450+
في الـsandbox أعلاه؛ المكونان `ProductTable` و `SearchBar` يقرآن الخصائص `filterText` و `inStockOnly` لعرض الجدول، مربع البحث، ومربع الاختيار. إليك مثلا كيف يقوم المكون `SearchBar` بكتابة محتوى مربع البحث:
449451
450452
```js {1,6}
451453
function SearchBar({ filterText, inStockOnly }) {
@@ -457,7 +459,7 @@ function SearchBar({ filterText, inStockOnly }) {
457459
placeholder="Search..."/>
458460
```
459461
460-
However, you haven't added any code to respond to the user actions like typing yet. This will be your final step.
462+
برغم ذلك، فأنت لم تقم بعد بكتابة أي كود للتجاوب مع تفاعلات المستخدم (كالكتابة). هذه ستكون خطوتك الأخيرة.
461463
462464
463465
## Step 5: Add inverse data flow {/*step-5-add-inverse-data-flow*/}

0 commit comments

Comments
 (0)