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

Describing UI structures

JSX is the best way to describe complex UI structures. Let's look at some JSX markup that declares a more elaborate structure than a single paragraph:

import React from 'react'; 
import { render } from 'react-dom'; 
 
// This JSX markup describes some fairly-sophisticated 
// markup. Yet, it's easy to read, because it's XML and 
// XML is good for concisely-expressing hierarchical 
// structure. This is how we want to think of our UI, 
// when it needs to change, not as an inpidual element 
// or property. 
render(( 
  <section> 
    <header> 
      <h1>A Header</h1> 
    </header> 
    <nav> 
      <a href="item">Nav Item</a> 
    </nav> 
    <main> 
      <p>The main content...</p> 
    </main> 
    <footer> 
      <small>&copy; 2016</small> 
    </footer> 
  </section> 
  ), 
  document.getElementById('app') 
); 

As you can see, there's a lot of semantic elements in this markup, describing the structure of the UI. The key is that this type of complex structure is easy to reason about, and we don't need to think about rendering specific parts of it. But before we start implementing dynamic JSX markup, let's create some of our own JSX components. Here is what the rendered content looks like:

主站蜘蛛池模板: 竹山县| 麦盖提县| 甘谷县| 曲麻莱县| 庄浪县| 菏泽市| 镶黄旗| 德江县| 论坛| 商南县| 丹江口市| 集贤县| 若尔盖县| 宣化县| 化州市| 车险| 蚌埠市| 江达县| 屏南县| 乌兰县| 巨鹿县| 常德市| 东乡族自治县| 栾川县| 武城县| 南安市| 应城市| 镇安县| 万州区| 盐边县| 萨迦县| 鄂州市| 永新县| 固安县| 姚安县| 宁明县| 秭归县| 抚远县| 林西县| 万全县| 陇川县|