官术网_书友最值得收藏!

Component-based architecture in React

Since its release in 2013, React has redefined the way that frontend applications should be built. It introduces the concept of component-based architecture, which, in essence, allows you to visualize your application as if it were made up of tiny, self-sustained view components. These view components are reusable; that is, a component such as CommentBox or Footer encapsulates the necessary functionality and can be used across the pages in the site.

A page in this context is itself a view component that is composed of other tiny view components, as shown here:

<Dashboard>
<Header>
<Brand />
</Header>
<SideNav>
<NavLink key=”1”>
<NavLink key=”2”>
</SideNav>
<ContentArea>
<Chart>
<Grid data="stockPriceList">
</ContentArea>
<Footer />
</Dashboard>

Here, <Dashboard> is a view component that encompasses several other view components (Header, SideNav, ContentArea, and Footer), which in turn are made up tiny components (Brand, NavLink, Chart, and Grid). The component-based architecture encourages you to build components that provide certain functionality and are not tightly coupled with any of their parent or sibling components. These components implement certain functionality and provide an interface through which they can be included in the page.

In the preceding example, a <Grid> component would include features such as rendering data in rows and columns, providing search functionality, and also an option to sort the columns either in ascending or descending order. The <Grid> component would implement all of the aforementioned features and provide an interface through which it can be included in the page. The interface here would include the tag name (Grid) and set of properties (props) that accept the values from its parent component. Here, the <Grid> component could interface with the backend system and retrieve the data; however, this would make the component tied tightly to the given backend interface, thus not making it reusable. Ideally, a view component would receive data from its parent component and act accordingly:

<Grid data="stockPriceList" />

Here, the <Grid> component receives a list containing stock price information through its data prop and would render this information in a tabular format. A component that includes this <Grid> component can be termed a Container component and Grid as a child component.

A Container component is also a View component; however, its responsibility includes providing its child components with the necessary data to render. A Container component could initiate HTTP calls to a backend service and receive the data required to render its child components. In addition to that, the Container component is also responsible for the positioning of the individual view components in its view area.

主站蜘蛛池模板: 岑巩县| 额尔古纳市| 弥渡县| 廊坊市| 科技| 靖远县| 崇文区| 萨嘎县| 临湘市| 托克托县| 左贡县| 海阳市| 汪清县| 伊金霍洛旗| 郁南县| 广汉市| 平乡县| 麻城市| 龙井市| 竹溪县| 阿勒泰市| 石城县| 海南省| 湟中县| 吉木萨尔县| 阿尔山市| 平湖市| 凤阳县| 颍上县| 邵阳市| 昌图县| 临朐县| 尚志市| 恭城| 石泉县| 新营市| 华阴市| 东乡县| 松江区| 锡林浩特市| 临夏市|