From 92ad9c2f7abb36a306f563fe48b7f52649929608 Mon Sep 17 00:00:00 2001 From: Emma Date: Sun, 23 Jun 2019 22:07:22 +0100 Subject: [PATCH 1/4] Update thinking-in-react.md (#2095) Please refer to https://justsimply.dev for the thinking behind these proposed changes. --- content/docs/thinking-in-react.md | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/content/docs/thinking-in-react.md b/content/docs/thinking-in-react.md index 7b2e2e7e6..25be9d812 100644 --- a/content/docs/thinking-in-react.md +++ b/content/docs/thinking-in-react.md @@ -35,13 +35,13 @@ Our JSON API returns some data that looks like this: The first thing you'll want to do is to draw boxes around every component (and subcomponent) in the mock and give them all names. If you're working with a designer, they may have already done this, so go talk to them! Their Photoshop layer names may end up being the names of your React components! -But how do you know what should be its own component? Just 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. +But how do you know what should be its own component? 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. -Since you're often displaying a JSON data model to a user, you'll find that if your model was built correctly, your UI (and therefore your component structure) will map nicely. That's because UI and data models tend to adhere to the same *information architecture*, which means the work of separating your UI into components is often trivial. Just break it up into components that represent exactly one piece of your data model. +Since you're often displaying a JSON data model to a user, you'll find that if your model was built correctly, your UI (and therefore your component structure) will map nicely. That's because UI and data models tend to adhere to the same *information architecture*, which means the work of separating your UI into components is often trivial. Break it up into components that represent exactly one piece of your data model. ![Component diagram](../images/blog/thinking-in-react-components.png) -You'll see here that we have five components in our simple app. We've italicized the data each component represents. +You'll see here that we have five components in our app. We've italicized the data each component represents. 1. **`FilterableProductTable` (orange):** contains the entirety of the example 2. **`SearchBar` (blue):** receives all *user input* @@ -51,7 +51,7 @@ You'll see here that we have five components in our simple app. We've italicized If you look at `ProductTable`, 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 there's an argument to be made either way. For this example, we left it as part of `ProductTable` because it is part of rendering the *data collection* which is `ProductTable`'s responsibility. However, if this header grows to be complex (i.e. if we were to add affordances for sorting), it would certainly make sense to make this its own `ProductTableHeader` component. -Now that we've identified the components in our mock, let's arrange them into a hierarchy. This is easy. Components that appear within another component in the mock should appear as a child in the hierarchy: +Now that we've identified the components in our mock, let's arrange them into a hierarchy. Components that appear within another component in the mock should appear as a child in the hierarchy: * `FilterableProductTable` * `SearchBar` @@ -70,9 +70,9 @@ To build a static version of your app that renders your data model, you'll want You can build top-down or bottom-up. That is, you can either start with building the components higher up in the hierarchy (i.e. starting with `FilterableProductTable`) or with the ones lower in it (`ProductRow`). In simpler examples, it's usually easier to go top-down, and on larger projects, it's easier to go bottom-up and write tests as you build. -At the end of this step, you'll have a library of reusable components that render your data model. The components will only have `render()` methods since this is a static version of your app. The component at the top of the hierarchy (`FilterableProductTable`) will take your data model as a prop. If you make a change to your underlying data model and call `ReactDOM.render()` again, the UI will be updated. It's easy to see how your UI is updated and where to make changes since there's nothing complicated going on. React's **one-way data flow** (also called *one-way binding*) keeps everything modular and fast. +At the end of this step, you'll have a library of reusable components that render your data model. The components will only have `render()` methods since this is a static version of your app. The component at the top of the hierarchy (`FilterableProductTable`) will take your data model as a prop. If you make a change to your underlying data model and call `ReactDOM.render()` again, the UI will be updated. You can see how your UI is updated and where to make changes. React's **one-way data flow** (also called *one-way binding*) keeps everything modular and fast. -Simply refer to the [React docs](/docs/) if you need help executing this step. +Refer to the [React docs](/docs/) if you need help executing this step. ### A Brief Interlude: Props vs State {#a-brief-interlude-props-vs-state} @@ -80,9 +80,9 @@ There are two types of "model" data in React: props and state. It's important to ## Step 3: Identify The Minimal (but complete) Representation Of UI State {#step-3-identify-the-minimal-but-complete-representation-of-ui-state} -To make your UI interactive, you need to be able to trigger changes to your underlying data model. React makes this easy with **state**. +To make your UI interactive, you need to be able to trigger changes to your underlying data model. React achieves this with **state**. -To build your app correctly, you first need to think of the minimal set of mutable state that your app needs. The key here is [DRY: *Don't Repeat Yourself*](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself). Figure out the absolute minimal representation of the state your application needs and compute everything else you need on-demand. For example, if you're building a TODO list, just keep an array of the TODO items around; don't keep a separate state variable for the count. Instead, when you want to render the TODO count, simply take the length of the TODO items array. +To build your app correctly, you first need to think of the minimal set of mutable state that your app needs. The key here is [DRY: *Don't Repeat Yourself*](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself). Figure out the absolute minimal representation of the state your application needs and compute everything else you need on-demand. For example, if you're building a TODO list, keep an array of the TODO items around; don't keep a separate state variable for the count. Instead, when you want to render the TODO count, take the length of the TODO items array. Think of all of the pieces of data in our example application. We have: @@ -91,7 +91,7 @@ Think of all of the pieces of data in our example application. We have: * The value of the checkbox * The filtered list of products -Let's go through each one and figure out which one is state. Simply ask three questions about each piece of data: +Let's go through each one and figure out which one is state. Ask three questions about each piece of data: 1. Is it passed in from a parent via props? If so, it probably isn't state. 2. Does it remain unchanged over time? If so, it probably isn't state. @@ -117,7 +117,7 @@ For each piece of state in your application: * Identify every component that renders something based on that state. * Find a common owner component (a single component above all the components that need the state in the hierarchy). * Either the common owner or another component higher up in the hierarchy should own the state. - * If you can't find a component where it makes sense to own the state, create a new component simply for holding the state and add it somewhere in the hierarchy above the common owner component. + * 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 owner component. Let's run through this strategy for our application: @@ -135,14 +135,12 @@ You can start seeing how your application will behave: set `filterText` to `"bal So far, we've built an app that renders correctly as a function of props and state flowing down the hierarchy. Now it's time to support data flowing the other way: the form components deep in the hierarchy need to update the state in `FilterableProductTable`. -React makes this data flow explicit to make it easy to understand how your program works, but it does require a little more typing than traditional two-way data binding. +React makes this data flow explicit to help you understand how your program works, but it does require a little more typing than traditional two-way data binding. If you try to type or check the box in the current version of the example, you'll see that React ignores your input. This is intentional, as we've set the `value` prop of the `input` to always be equal to the `state` passed in from `FilterableProductTable`. Let's think about what we want to happen. We want to make sure that whenever the user changes the form, we update the state to reflect the user input. Since components should only update their own state, `FilterableProductTable` will pass callbacks to `SearchBar` that will fire whenever the state should be updated. We can use the `onChange` event on the inputs to be notified of it. The callbacks passed by `FilterableProductTable` will call `setState()`, and the app will be updated. -Though this sounds complex, it's really just a few lines of code. And it's really explicit how your data is flowing throughout the app. - ## And That's It {#and-thats-it} -Hopefully, this gives you an idea of how to think about building components and applications with React. While it may be a little more typing than you're used to, remember that code is read far more than it's written, and it's extremely easy to read this modular, explicit code. As you start to build large libraries of components, you'll appreciate this explicitness and modularity, and with code reuse, your lines of code will start to shrink. :) +Hopefully, this gives you an idea of how to think about building components and applications with React. While it may be a little more typing than you're used to, remember that code is read far more than it's written, and it's less difficult to read this modular, explicit code. As you start to build large libraries of components, you'll appreciate this explicitness and modularity, and with code reuse, your lines of code will start to shrink. :) From 39f30d42115ef9968c71d2ceaf04b6140c0a24c9 Mon Sep 17 00:00:00 2001 From: Emma Date: Mon, 24 Jun 2019 22:54:37 +0100 Subject: [PATCH 2/4] Update thinking-in-react.md (#2098) Follow up to https://github.com/reactjs/reactjs.org/pull/2095#discussion_r296498172 --- content/docs/thinking-in-react.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/docs/thinking-in-react.md b/content/docs/thinking-in-react.md index 25be9d812..12b2712ee 100644 --- a/content/docs/thinking-in-react.md +++ b/content/docs/thinking-in-react.md @@ -37,7 +37,7 @@ The first thing you'll want to do is to draw boxes around every component (and s But how do you know what should be its own component? 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. -Since you're often displaying a JSON data model to a user, you'll find that if your model was built correctly, your UI (and therefore your component structure) will map nicely. That's because UI and data models tend to adhere to the same *information architecture*, which means the work of separating your UI into components is often trivial. Break it up into components that represent exactly one piece of your data model. +Since you're often displaying a JSON data model to a user, you'll find that if your model was built correctly, your UI (and therefore your component structure) will map nicely. That's because UI and data models tend to adhere to the same *information architecture*. Separate your UI into components, where each component matches one piece of your data model. ![Component diagram](../images/blog/thinking-in-react-components.png) From cb5a61cdbfa5e72646cfb954056c6a4fde490a8c Mon Sep 17 00:00:00 2001 From: Riley Avron Date: Tue, 25 Jun 2019 17:15:19 -0700 Subject: [PATCH 3/4] Add missing function call to example (#2102) An example for useEffect omitted the actual invocation of the function in question. --- content/docs/hooks-faq.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/content/docs/hooks-faq.md b/content/docs/hooks-faq.md index 12e1db0b7..a61e99e9c 100644 --- a/content/docs/hooks-faq.md +++ b/content/docs/hooks-faq.md @@ -610,7 +610,7 @@ function ProductPage({ productId }) { This also allows you to handle out-of-order responses with a local variable inside the effect: -```js{2,6,8} +```js{2,6,10} useEffect(() => { let ignore = false; async function fetchProduct() { @@ -618,6 +618,8 @@ This also allows you to handle out-of-order responses with a local variable insi const json = await response.json(); if (!ignore) setProduct(json); } + + fetchProduct(); return () => { ignore = true }; }, [productId]); ``` From e4817e675a36aa0202e7b74a576b17353a07e491 Mon Sep 17 00:00:00 2001 From: Erdenezul Batmunkh Date: Thu, 27 Jun 2019 09:10:53 +0200 Subject: [PATCH 4/4] Fix conflict --- content/docs/thinking-in-react.md | 96 ------------------------------- 1 file changed, 96 deletions(-) diff --git a/content/docs/thinking-in-react.md b/content/docs/thinking-in-react.md index 2c271580e..be204c238 100644 --- a/content/docs/thinking-in-react.md +++ b/content/docs/thinking-in-react.md @@ -35,8 +35,6 @@ React-н олон гайхалтай хэсгүүдийн нэг нь веб п Эхний хийх зүйл бол загвар дээр байгаа компонент болгонд(мөн түүний дэд компонентод) хайрцаг зурах бөгөөд бүгдэнд нь нэр өгөх юм. Хэрэв та дизайнертайгаа цуг ажиллаж байгаа бол магадгүй тэд аль хэдийн хийчихсэн байж мэднэ. Тиймээс очоод ярилцаад үз! Тэдний Photoshop давхаргын нэрнүүд нь таны React компонентүүдийн нэр байж болох юм! -<<<<<<< HEAD -<<<<<<< HEAD Гэхдээ та хэрхэн энэ өөрөө компонент болох вэ гэдгээ мэдэх вэ? Та код бичихдээ шинэ функц болон объект үүсгэхдээ ашигладаг аргаа л ашиглана. Эдгээр аргуудын нэг нь [ганц хариуцлагатай ухагдахуун](https://en.wikipedia.org/wiki/Single_responsibility_principle) бөгөөд нэг компонент нэг л зүйл хийдэг. Хэрэв үйлдэл нь өсөөд эхэлбэл тэдгээрийг жижиг дэд компонентууд болгон салгах нь зүйтэй. Та ихэвчлэн JSON өгөгдлийн загвар хэрэглэгч рүү дүрсэлж байгаагаас хойш хэрэв таны загвар(model) зөв бичигдсэн бол таны дэлгэцийн загвар(мөн түүнчлэн таны компонент бүтэц) яг сайхан нийцэх ёстой. Учир нь дэлгэцийн загвар болон өгөгдлйин загварууд нь ижилхэн *мэдээллийн архитектур*-тай байхийг шаарддаг. Өөрөөр хэлбэл дэлгэцийн загварын ажлаа тусад нь салгах нь ач холбогдолгүй юм. Зүгээр л өгөгдлийн загварынхаа нэг хэсгийг компонент болгон салга. @@ -44,24 +42,6 @@ React-н олон гайхалтай хэсгүүдийн нэг нь веб п ![Component diagram](../images/blog/thinking-in-react-components.png) Бидний энгийн програмд таван компонентууд байгааг харж болно. Бид компонент бүрийг төлөөлсөн өгөгдлийг налуу болгосон. -======= -But how do you know what should be its own component? 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. -======= -But how do you know what should be its own component? 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. - -Since you're often displaying a JSON data model to a user, you'll find that if your model was built correctly, your UI (and therefore your component structure) will map nicely. That's because UI and data models tend to adhere to the same *information architecture*. Separate your UI into components, where each component matches one piece of your data model. - -![Component diagram](../images/blog/thinking-in-react-components.png) - -You'll see here that we have five components in our app. We've italicized the data each component represents. ->>>>>>> cb5a61cdbfa5e72646cfb954056c6a4fde490a8c - -Since you're often displaying a JSON data model to a user, you'll find that if your model was built correctly, your UI (and therefore your component structure) will map nicely. That's because UI and data models tend to adhere to the same *information architecture*, which means the work of separating your UI into components is often trivial. Break it up into components that represent exactly one piece of your data model. - -![Component diagram](../images/blog/thinking-in-react-components.png) - -You'll see here that we have five components in our app. We've italicized the data each component represents. ->>>>>>> 92ad9c2f7abb36a306f563fe48b7f52649929608 1. **`FilterableProductTable` (улбар шар):** жишээг бүгдийг багтаасан 2. **`SearchBar` (цэнхэр):** бүх *хэрэглэгчийн оролm*-ыг хүлээн авна @@ -71,15 +51,7 @@ You'll see here that we have five components in our app. We've italicized the da Хэрэв та `ProductTable`-г харвал та хүснэгтийн толгой("Нэр" болон "Үнэ" агуулсан) өөрийн гэсэн компонентгүй байгааг харна. Тусад компонент хийх эсэх нь таны сонголтын л асуудал юм. Жишээлбэл `ProductTable` энэ байгаа чигээр нь үлдээгээд хүснэгтийн толгой хэвлэх нь өгөгдөл дүрслэхийн нэг хэсэг гэж үзэж болох юм. Гэхдээ хүснэгтийн толгой илүү цогц болвол(жишээ нь бид эрэмблэх сонголт нэмэх бол) тусад нь `ProductTableHeader` компонент үүсгэх нь илүү дээр байж болно. -<<<<<<< HEAD -<<<<<<< HEAD За одоо бид анхны загварын компонентуудаа мэдэж авсан бол шатлал бүтцэд оруулан эрэмблэе. Энэ нь амархан. Загвар дээр өөр нэг компонент дотор харагдаж байгаа компонент шатлалт бүтцээрээ дэд компонент болно: -======= -Now that we've identified the components in our mock, let's arrange them into a hierarchy. Components that appear within another component in the mock should appear as a child in the hierarchy: ->>>>>>> 92ad9c2f7abb36a306f563fe48b7f52649929608 -======= -Now that we've identified the components in our mock, let's arrange them into a hierarchy. Components that appear within another component in the mock should appear as a child in the hierarchy: ->>>>>>> cb5a61cdbfa5e72646cfb954056c6a4fde490a8c * `FilterableProductTable` * `SearchBar` @@ -99,46 +71,20 @@ Now that we've identified the components in our mock, let's arrange them into a Та доороос дээш эсвэл дээрээс доош арга ашиглан бичиж болно. ЭНэ нь компонентийн шатлалын бүтцийн дээд талын(`FilterProductTable`-с эхлэх) эсвэл доод талаас(`ProductRow`) эхэлж болно гэсэн үг. Ихэвчлэн дээрээс доош арга нь илүү амархан байдаг ба том төсөлд доороос дээш аргийг ашиглахад тест бичихэд амархан болдог. -<<<<<<< HEAD -<<<<<<< HEAD Энэ алхмын төгсгөлд та өгөгдлийн загвараа дүрслэх дахин ашиглагдахуйц компонентийн сантай болно. Статик хувилбард Компонентууд нь зөвхөн `render()` аргийг(method) хэрэгжүүлсэн байна. Шатлалын дээд талын компонент(`FilterableProductTable`) өгөгдлийн загварын шинж чанараар авна. Хэрэв та өгөгдөлдөө өөрчлөлт хийсэн бол `ReactDOM.render()` дахин дуудагдаж дэлгэцийн загвар шинэчлэгдэх болно. Энэ нь өөрчлөлт хийхэд таны дэлгэцийн загвар хэрхэн шинэчлэгдэж байгааг харахад амар болгоно. React-н **нэг чиглэлт өгөгдлийн урсгал** (мөн *нэг чиглэлт холболт(one-way binding)* гэж нэрлэдэг) нь бүхнийг модулар байдлаар үлдээн хурдан болгодог. Энэ алхмийг ажиллуулахад тусламж хэрэгтэй бол [React баримтжуулалт](/docs/) руу орно уу. -======= -At the end of this step, you'll have a library of reusable components that render your data model. The components will only have `render()` methods since this is a static version of your app. The component at the top of the hierarchy (`FilterableProductTable`) will take your data model as a prop. If you make a change to your underlying data model and call `ReactDOM.render()` again, the UI will be updated. You can see how your UI is updated and where to make changes. React's **one-way data flow** (also called *one-way binding*) keeps everything modular and fast. -======= -At the end of this step, you'll have a library of reusable components that render your data model. The components will only have `render()` methods since this is a static version of your app. The component at the top of the hierarchy (`FilterableProductTable`) will take your data model as a prop. If you make a change to your underlying data model and call `ReactDOM.render()` again, the UI will be updated. You can see how your UI is updated and where to make changes. React's **one-way data flow** (also called *one-way binding*) keeps everything modular and fast. - -Refer to the [React docs](/docs/) if you need help executing this step. ->>>>>>> cb5a61cdbfa5e72646cfb954056c6a4fde490a8c - -Refer to the [React docs](/docs/) if you need help executing this step. ->>>>>>> 92ad9c2f7abb36a306f563fe48b7f52649929608 - ### Бяцхан завсарлага: Шинж чанар эсвэл Төлөв {#a-brief-interlude-props-vs-state} -<<<<<<< HEAD React-д хоёр төрлийн өгөгдлийн загвар байдаг: props болон state. Энэ хоёрын ялгааг ойлгох нь чухал; Хэрэв та ялгааг нь сайн мэддэгтээ итгэлгүй бол [React албан ёсны баримтжуулалт](/docs/interactivity-and-dynamic-uis.html)-ыг гүйлгэн харна уу. -<<<<<<< HEAD ## Алхам 3: Дэлгэцийн загварын төлвийг минимал(гэхдээ бүрэн) мэдэх нь {#step-3-identify-the-minimal-but-complete-representation-of-ui-state} Та дэлгэцийн загвараа идэвхитэй(interactive) болгохийн өгөгдлийн загварын өөрчлөлтийг мэдэрж чаддаг байх хэрэгтэй. React үүнийг **төлөв**-р амархан хийдэг. Програмаа зөв бичихийн тулд таны програмийн өөрчлөгдөж болох төлвүүдийг минимал байдлаар бодох хэрэгтэй. Арга нь [DRY: *Don't Repeat Yourself*](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself). Програмийн төлвийн минимал төлөөллийг бодож олохийн тулд танд хэрэгтэй бүхнийг тооцоол. Жишээлбэл, хийх зүйлийн жагсаалт хийх гэж байгаа бол хийх зүйл нь массивт хадгалж болох ч хийх зүйлийн жагсаалтаа тоолохдоо нэмж хувьсагч битгий ашиглаарай. Үүнийн оронд хийх зүйлээ хадгалж байгаа жагсаалтийн уртаа тоолоход л хангалттай. -======= -To make your UI interactive, you need to be able to trigger changes to your underlying data model. React achieves this with **state**. - -To build your app correctly, you first need to think of the minimal set of mutable state that your app needs. The key here is [DRY: *Don't Repeat Yourself*](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself). Figure out the absolute minimal representation of the state your application needs and compute everything else you need on-demand. For example, if you're building a TODO list, keep an array of the TODO items around; don't keep a separate state variable for the count. Instead, when you want to render the TODO count, take the length of the TODO items array. ->>>>>>> 92ad9c2f7abb36a306f563fe48b7f52649929608 -======= -To make your UI interactive, you need to be able to trigger changes to your underlying data model. React achieves this with **state**. - -To build your app correctly, you first need to think of the minimal set of mutable state that your app needs. The key here is [DRY: *Don't Repeat Yourself*](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself). Figure out the absolute minimal representation of the state your application needs and compute everything else you need on-demand. For example, if you're building a TODO list, keep an array of the TODO items around; don't keep a separate state variable for the count. Instead, when you want to render the TODO count, take the length of the TODO items array. ->>>>>>> cb5a61cdbfa5e72646cfb954056c6a4fde490a8c -Think of all of the pieces of data in our example application. We have: Жишээ програмын өгөгдлийн хэсэг болгонийг бодоорой. Бидэнд: * Барааны жагсаалт @@ -146,15 +92,7 @@ Think of all of the pieces of data in our example application. We have: * Чеклэсэн утга * Шүүгдсэн барааны жагсаалт -<<<<<<< HEAD -<<<<<<< HEAD Эдгээр бүгдийг аль нь төлөв болохийг тогтооцгооё. Дараах 3 асуултыг өгөгдлийн хэсэг болгон дээр тавиарай: -======= -Let's go through each one and figure out which one is state. Ask three questions about each piece of data: ->>>>>>> 92ad9c2f7abb36a306f563fe48b7f52649929608 -======= -Let's go through each one and figure out which one is state. Ask three questions about each piece of data: ->>>>>>> cb5a61cdbfa5e72646cfb954056c6a4fde490a8c 1. Эцэг компонентоос шинж чанараар дамжин ирсэн үү? Тийм бол энэ нь магадгүй төлөв биш юм. 2. Энэ нь өөрчлөгдөхгүй үлдэх үү? Тийм бол энэ нь магадгүй төлөв биш юм. @@ -178,20 +116,10 @@ React нь компонентийн шатлалын доошоо нэг урс Таны програмын төлөв болгон дээр: -<<<<<<< HEAD * Энэ төлөв дээр тулгуурлан ямар нэг зүйл дүрсэлж байгаа компонентийг тодорхойлно. * Нийтлэг эзэмшигч компонентийг хайж олох (төлөв хэрэгтэй байгаа бүх компонентүүдийн шатлалын дээд талын компонент). * Нийтлэг эзэмшигч эсвэл шатлалын дээд талд байнаа өөр нэг компонент төлвийг эзэмших хэрэгтэй. * Та ямар нэг төлөв эзэмших ёстой гэж бодож байгаа компонент олж чадахгүй бол шинээр компонент үүсгэн шатлалын дээд талд нь нэмнэ. -======= - * Identify every component that renders something based on that state. - * Find a common owner component (a single component above all the components that need the state in the hierarchy). - * Either the common owner or another component higher up in the hierarchy should own the state. - * 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 owner component. -<<<<<<< HEAD ->>>>>>> 92ad9c2f7abb36a306f563fe48b7f52649929608 -======= ->>>>>>> cb5a61cdbfa5e72646cfb954056c6a4fde490a8c Энэ аргачлалийг өөрдийн програмдаа хэрэгжүүлье: @@ -209,34 +137,10 @@ React нь компонентийн шатлалын доошоо нэг урс За бид програмаа өгөгдлөө зөв дүрслэн шатлалаас доошоо төлөв болон шинж чанараа зөв дамжуулан хийлээ. Одоо бид өгөгдлийг эсрэг чиглэлд дамжуулах цаг боллоо: шатлалын гүнд байнаа форм компонентууд `FilterableProductTable`-н төлвийг шинэчлэх хэрэгтэй байна. -<<<<<<< HEAD -<<<<<<< HEAD React энэ өгөгдлийн урсгалын тусгайлан хийдэг бөгөөд энэ нь таны програм хэрхэн ажилдгийг ойлгоход амар болгодог уламжлалт хоёр чиглэлтэй өгөгдлийн холболтоос бага зэрэг их бичиглэл шаардана. -======= -React makes this data flow explicit to help you understand how your program works, but it does require a little more typing than traditional two-way data binding. ->>>>>>> 92ad9c2f7abb36a306f563fe48b7f52649929608 -======= -React makes this data flow explicit to help you understand how your program works, but it does require a little more typing than traditional two-way data binding. ->>>>>>> cb5a61cdbfa5e72646cfb954056c6a4fde490a8c -If you try to type or check the box in the current version of the example, you'll see that React ignores your input. This is intentional, as we've set the `value` prop of the `input` to always be equal to the `state` passed in from `FilterableProductTable`. - -Бид юу хүсэж байгаагаа жаахан бодоё. Хэрэглэгчийг форм өөрчлөх бүрд хэрэглэгчийн оролтод тулгуурлан төлвөө яг зэрэг солих хэрэгтэй байна. Компонент нь зөвхөн өөрийнхөө төлвийг л шинэчилж чадах учир `FilterableProductTable` нь `SearchBar` руу эргэн дуудагддаг(callback) функц дамжуулан төлвөө сольж болно. Бид `onChange` эвентийг ашиглан өөрчлөлтийг мэдэрж болно. `FilterableProductTable`-с дамжуулагдсан эргэн дуудагдах функц нь `setState()`-г дуудан програм шинэчлэгдэх юм. - -<<<<<<< HEAD Бага зэрэг ярвигтай санагдаж болох ч энэ хэдхэн мөр код юм. Мөн энэ нь таны програмын дотор өгөгдөл хэрхэн урсахийг тодорхой заасан болно. -<<<<<<< HEAD ## За боллоо {#and-thats-it} Энэхүү бичвэр танд компонент болон програм React дээр бичихдээ хэрхэн сэтгэх талаар ойлголт өгсөн гэж найдая. Энэ нь бага зэрэг илүү бичиглэл шаардаж байгаа энэхүү модулар бүтэтэй тодорхой код нь уншиж ойлгоход дэндүү амархан болгож байна. Компонентийн том сан бичих үед энэхүү ойлгомжтой байдал, модулар бүтэц, кодын дахин ашиглагдах байдалд танд тус болохоос гадна бичиглэлийн тоо ч багасч эхэлнэ. -======= -## And That's It {#and-thats-it} - -Hopefully, this gives you an idea of how to think about building components and applications with React. While it may be a little more typing than you're used to, remember that code is read far more than it's written, and it's less difficult to read this modular, explicit code. As you start to build large libraries of components, you'll appreciate this explicitness and modularity, and with code reuse, your lines of code will start to shrink. :) ->>>>>>> 92ad9c2f7abb36a306f563fe48b7f52649929608 -======= -## And That's It {#and-thats-it} - -Hopefully, this gives you an idea of how to think about building components and applications with React. While it may be a little more typing than you're used to, remember that code is read far more than it's written, and it's less difficult to read this modular, explicit code. As you start to build large libraries of components, you'll appreciate this explicitness and modularity, and with code reuse, your lines of code will start to shrink. :) ->>>>>>> cb5a61cdbfa5e72646cfb954056c6a4fde490a8c