3.5. React component

发布时间 : 2025-10-25 13:34:30 UTC      

Page Views: 9 views

In this section we will discuss how to use components to make our application easier to manage.

Next, let’s package an output “Hello World!” Component named HelloMessage :

3.5.1. React instance

functionHelloMessage(props){return

HelloWorld!

;}constelement= ;ReactDOM.render(element,document.getElementById('example'));

Instance resolution:

1.We can use the function to define a component:

function HelloMessage(props) { return 

Hello World!

; }

You can also use ES6 class to define a component:

class Welcome extends React.Component { render() { return 

Hello World!

; } }

2、 const element = /> 为用户自定义的组件。

Note that native HTML element names start with lowercase letters, while custom React class names start with uppercase letters, such as HelloMessage can’t be written as helloMessage . In addition, it is important to note that the component class can only contain a top-level tag, otherwise an error will also be reported.

If we need to pass parameters to the component, we can use the this.props object. An example is as follows:

3.5.2. React instance

functionHelloMessage(props){return

Hello{props.name}!

;}constelement= ;ReactDOM.render(element,document.getElementById('example'));

In the above example name property through the props.name to get.

Note that when adding attributes, the class attribute needs to be written as className , and the for attribute needs to be written as htmlFor because’ class’ and for are reserved words in JavaScript.

Composite component

We can synthesize a component by creating multiple components, that is, separating the different function points of the component.

In the following example, we implement a component that outputs the name and URL of the website:

3.5.3. React instance

functionName(props){return

Site Name:{props.name}

;}functionUrl(props){return

Website address:{props.url}

;}functionNickname(props){return

Website nickname:{props.nickname}

;}functionApp(){return(
);}ReactDOM.render(,document.getElementById('example'));

The App component in the instance uses the Name Url and Nickname component to output the corresponding information.

《地理信息系统原理、技术与方法》  97

最近几年来,地理信息系统无论是在理论上还是应用上都处在一个飞速发展的阶段。 GIS被应用于多个领域的建模和决策支持,如城市管理、区划、环境整治等等,地理信息成为信息时代重要的组成部分之一; “数字地球”概念的提出,更进一步推动了作为其技术支撑的GIS的发展。 与此同时,一些学者致力于相关的理论研究,如空间感知、空间数据误差、空间关系的形式化等等。 这恰好说明了地理信息系统作为应用技术和学科的两个方面,并且这两个方面构成了相互促进的发展过程。