React组件

1. 什么是组件?

组件是由元素构成的一个聚合体

2. React - 函数组件

定义组件最简单的方式就是编写 JavaScript 函数:

    /* 声明函数组件 */
    function Welcome(props) {
        return <h1>Hello, {props.name}</h1>;
    }
    //OR
    const Hello = props => <h1> Hello React函数组件 </h1>

3. React - 类组件

我们还可以使用 ES6 的 class 来定义组件

    /* 声明类组件 */
    import React,{ Component } from 'react'
    class Welcome extends Component{
        render () { // 通过render函数来渲染一个jsx结构
            return (
                <div>
                    欢迎使用西阁的React笔记
                <div>
            )
        }
    }

results matching ""

    No results matching ""