zhiqingstudy

Be a young person with knowledge and content

Components are first-class citizens of React, and when you use react, you are using components

A component represents a subset of functionality in a page

Combine multiple components to achieve complete page functionality

Component features: reusable, independent, combinable

There are two ways to create a react component

1. Create a component using a function

Function Component: A component created using a function (or head-cutting function) from JS

Convention 1: Function names must start with a capital letter

Convention 2: A function component must have a return value that represents the structure of the component

If the return value is null, nothing is rendered

function Hello(){
   return (<div>这是一个函数组件</div>)
}
ReactDOM.render(<Hello />,document.querySelector('#root'))

2. Create a component with a class

Class Component: Use ES6 class to create a component

Convention 1: Class names must start with a capital letter

Convention 2: Class components should inherit from the React.Component parent class, allowing you to use the methods and properties provided in the parent class

Convention 3: Class components must provide a render() method

Convention 4: The render() method must have a return value that represents the structure of the component

class Hello extends React.Component {
    render(){
        return (<div>Hello class Component</div>)
    }
}
ReactDOM.render(<Hello />,document.querySelector('#root'))
comment
head sculpture
Code:
Related

The art of interpersonal communication and communication

A code of conduct that regulates and regulates interpersonal relationships

The importance of interpersonal relationships




Unless otherwise specified, all content on this website is original. If the reprinted content infringes on your rights, please contact the administrator to delete it
Contact Email:2380712278@qq.com

Filing number:皖ICP备19012824号