Skip to content

Commit 3627674

Browse files
committed
thinking in react - part 2
1 parent 3bc6416 commit 3627674

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

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

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,51 +33,55 @@ React дээр UI-аа бүтээхдээ дараах 5 алхамыг дага
3333

3434
## Алхам 1: UI-аа компонентын шатлал болгон салгая {/*step-1-break-the-ui-into-a-component-hierarchy*/}
3535

36-
Start by drawing boxes around every component and subcomponent in the mockup and naming them. If you work with a designer, they may have already named these components in their design tool. Ask them!
36+
Эхлээд бүх компонент болон дэд компонентуудыг mock загварын дагуу зурж тэдгээрийг нэрлэнэ. Хэрвээ та дизайнертайгаа ажиллаж байгаа бол тэд аль хэдийн диэайн зурдаг хэрэгсэл дээрээ нэрлэсэн байж магадгүй. Тэднээс асуугаарай.
3737

3838
Depending on your background, you can think about splitting up a design into components in different ways:
3939

40-
* **Programming**--use the same techniques for deciding if you should create a new function or object. One such technique is the [single responsibility principle](https://en.wikipedia.org/wiki/Single_responsibility_principle), that is, a component should ideally only do one thing. If it ends up growing, it should be decomposed into smaller subcomponents.
41-
* **CSS**--consider what you would make class selectors for. (However, components are a bit less granular.)
42-
* **Design**--consider how you would organize the design's layers.
40+
Таны юу хийдгээс хамааран өөр, өөр арга замаар хуваасан байж магадгүй юм.
41+
42+
* **Програмчилалын**--Шинээр функц болон объект үүсгэхдээ нэгэн ижил текник ашиглаарай. Нэг санал болгох текник нь [single responsibility principle](https://en.wikipedia.org/wiki/Single_responsibility_principle) ба энэ нь компонент бүр нэгээс илүү үйлдэл хийхгүй гэсэн санаа юм. Хэрвээ цаашид томрохоор болвол дэд компонентүүдэд задлах хэрэгэтй.
43+
* **CSS**--Класс селектороо юунд ашиглахааа шийдэх.
44+
* **Дизайн**--Дизайны давхаргуудаа хэрхэн зохион байгуулахаа шийдэх.
4345

4446
If your JSON is well-structured, you'll often find that it naturally maps to the component structure of your UI. That's because UI and data models often have the same information architecture--that is, the same shape. Separate your UI into components, where each component matches one piece of your data model.
4547

46-
There are five components on this screen:
48+
Хэрхээ таны JSON маш сайн бүтэцлэгдсэн бол таны UI-ын компонентуудтай шууд холбогдож ажиллаж чадна. Энэ нь UI болон өгөгдлийн моделууд ижил бүтэцтэй байх хэрэгтэй шалтгаан юм.
49+
50+
Дараах дэлгэцэнд 5 компонент байна:
4751

4852
<FullWidth>
4953

5054
<CodeDiagram flip>
5155

5256
<img src="/images/docs/s_thinking-in-react_ui_outline.png" width="500" style={{margin: '0 auto'}} />
5357

54-
1. `FilterableProductTable` (grey) contains the entire app.
55-
2. `SearchBar` (blue) receives the user input.
56-
3. `ProductTable` (lavender) displays and filters the list according to the user input.
57-
4. `ProductCategoryRow` (green) displays a heading for each category.
58-
5. `ProductRow` (yellow) displays a row for each product.
58+
1. `FilterableProductTable` (саарал) бүтэн апп-ыг багтаатсан.
59+
2. `SearchBar` (цэнхэр) хэрэглэгчийн оролтын хүлээж авах.
60+
3. `ProductTable` (лаванда) хэрэглэгчийн оролтын дагуу жагсаалтыг шүүж харуулах.
61+
4. `ProductCategoryRow` (ногоон) ангилал бүрийн толгой харуулах.
62+
5. `ProductRow` (шар) бүтээгдэхүүний мөрийг харуулах.
5963

6064
</CodeDiagram>
6165

6266
</FullWidth>
6367

64-
If you look at `ProductTable` (lavender), you'll see that the table header (containing the "Name" and "Price" labels) isn't its own component. This is a matter of preference, and you could go either way. For this example, it is a part of `ProductTable` because it appears inside the `ProductTable`'s list. However, if this header grows to be complex (e.g., if you add sorting), you can move it into its own `ProductTableHeader` component.
68+
Хэрвээ `ProductTable` (лаванда)-г харах юм бол, та хүснэгтийн толгой ("Name" ба "Price") нь тусдаа компонент биш байгааг анзаарна. Энэ нь гэхдээ сонголтын асуудал юм. Энэ жишээнд энэ нь `ProductTable` -ын нэг хэсэг юм. Гэхдээ хэрвээ толгой хэсэг цаашид нэмэгдэхээр бол (жишээ нь эрэмбэлэгдэх хэсэг), та тусдаа `ProductTableHeader` гэдэг нэртэй компонент шинээр үүсгэж болох юм.
6569

66-
Now that you've identified the components in the mockup, arrange them into a hierarchy. Components that appear within another component in the mockup should appear as a child in the hierarchy:
70+
Одоо mock дизайн дээрх компонентүүдийг шаталсан бүтцээр харуулцгаая.
6771

6872
* `FilterableProductTable`
6973
* `SearchBar`
7074
* `ProductTable`
7175
* `ProductCategoryRow`
7276
* `ProductRow`
7377

74-
## Step 2: Build a static version in React {/*step-2-build-a-static-version-in-react*/}
78+
## Step 2: React дээр статик хувилбараар хийцгээе {/*step-2-build-a-static-version-in-react*/}
7579

76-
Now that you have your component hierarchy, it's time to implement your app. The most straightforward approach is to build a version that renders the UI from your data model without adding any interactivity... yet! It's often easier to build the static version first and add interactivity later. Building a static version requires a lot of typing and no thinking, but adding interactivity requires a lot of thinking and not a lot of typing.
80+
Бид компонентын шаталсан бүтцээ гаргаад авсан, одоо апп-аа хийж эхэлцгээе. Хамгийн хялбар арга нь ямар нэгэн интерактив үйлдэлгүйгээр өгөгдлийн моделоосоо UI-аа үүсгэх юм... эхлээд статик хувилбарыг үүсгээд дараа нь интерактив үйлдлийг гүйцэтгэх нь илүү хялбар байдаг. Статик хувилбарыг үүсгэх нь илүү их бичихийг шаарддаг бол интерактив үйлдэл нь бага бичиж их бодохыг шаарддаг.
7781

78-
To build a static version of your app that renders your data model, you'll want to build [components](/learn/your-first-component) that reuse other components and pass data using [props.](/learn/passing-props-to-a-component) Props are a way of passing data from parent to child. (If you're familiar with the concept of [state](/learn/state-a-components-memory), don't use state at all to build this static version. State is reserved only for interactivity, that is, data that changes over time. Since this is a static version of the app, you don't need it.)
82+
Статик хувилбараа үүсгэхдээ та ахин ашиглагдах боломжтой [компонентүүд](/learn/your-first-component) үүсгэж [проп.](/learn/passing-props-to-a-component) ашиглан өгөгдлөө дамжуулах хэрэгтэй. Проп бол эцэг компонентоос хүү компонент руу өгөгдөл дамжуулах арга юм. (Хэрвээ та [стэйт](/learn/state-a-components-memory)-ийн талаар ойлголттой бол статик хувилбарыг үүсгэхдээ битгий ашиглаарай. Стэйт зөвхөн интерактив үйлдлүүд дээр ашиглагдах ба статик хувилбар хийж байхдаа шаардлагагүй юм.)
7983

80-
You can either build "top down" by starting with building the components higher up in the hierarchy (like `FilterableProductTable`) or "bottom up" by working from components lower down (like `ProductRow`). In simpler examples, it’s usually easier to go top-down, and on larger projects, it’s easier to go bottom-up.
84+
Та "дээрээс доошоо" буюу `FilterableProductTable` компонентоос эсвэл "доороос дээшээ" буюу `ProductRow`-оос эхлэн хийж болно. Жижгэвтэр жишээн дээр дээрээс доошоо чиглэл илүү тохиромжтой бол том төсөл дээр доороос дээшээ чиглэл илүү тохиромжтой.
8185

8286
<Sandpack>
8387

@@ -195,13 +199,13 @@ td {
195199

196200
</Sandpack>
197201

198-
(If this code looks intimidating, go through the [Quick Start](/learn/) first!)
202+
(Хэрвээ энэ код ойлгомжгүй бол эхлээд [Хурдан эхлэх](/learn/) хэсэг рүү очно уу!)
199203

200-
After building your components, you'll have a library of reusable components that render your data model. Because this is a static app, the components will only return JSX. The component at the top of the hierarchy (`FilterableProductTable`) will take your data model as a prop. This is called _one-way data flow_ because the data flows down from the top-level component to the ones at the bottom of the tree.
204+
Компонентуудаа үүсгэсэний дараа та ахин ашиглагдах компонентуудтай болсон байх болно. Яагаад гэвэл энэ статик хувилбар компонентууд зөвхөн JSX буцаана. Шаталсан бүтцийн дээр байгаа (`FilterableProductTable`) компонент проп-оороо өгөгдлийн модел хүлээн авна. Үүнийг нэг чиглэлт өгөгдлийн урсгал гэж нэрлэдэг ба өгөгдөл зөвхөн дээрээс доошоо дамжина.
201205

202206
<Pitfall>
203207

204-
At this point, you should not be using any state values. That’s for the next step!
208+
Та энэ удаад стэйт ашиглах хэрэггүй юм.
205209

206210
</Pitfall>
207211

0 commit comments

Comments
 (0)