3.5. React component

发布时间 :2024-03-15 23:00:03 UTC      

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<h1>HelloWorld!</h1>;}constelement=
<HelloMessage/>;ReactDOM.render(element,document.getElementById('example'));

Instance resolution:

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

function HelloMessage(props) {
    return <h1>Hello World!</h1>;
}

You can also use ES6 class to define a component:

class Welcome extends React.Component {
  render() {
    return <h1>Hello World!</h1>;
  }
}

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

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<h1>Hello{props.name}!</h1>;}constelement=
<HelloMessagename="Runoob"/>;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<h1>Site Name:{props.name}</h1>;}functionUrl(props){return<h1>
Website address:{props.url}</h1>;}functionNickname(props){return<h1>
Website nickname:{props.nickname}</h1>;}functionApp(){return(<div>
<Namename="Rookie Tutorial"/> <Urlurl="http://www.runoob.com"/>
<Nicknamenickname="Runoob"/>
</div>);}ReactDOM.render(<App/>,document.getElementById('example'));

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

Principles, Technologies, and Methods of Geographic Information Systems  102

In recent years, Geographic Information Systems (GIS) have undergone rapid development in both theoretical and practical dimensions. GIS has been widely applied for modeling and decision-making support across various fields such as urban management, regional planning, and environmental remediation, establishing geographic information as a vital component of the information era. The introduction of the “Digital Earth” concept has further accelerated the advancement of GIS, which serves as its technical foundation. Concurrently, scholars have been dedicated to theoretical research in areas like spatial cognition, spatial data uncertainty, and the formalization of spatial relationships. This reflects the dual nature of GIS as both an applied technology and an academic discipline, with the two aspects forming a mutually reinforcing cycle of progress.