Study Notes on official website

Source: Internet
Author: User

First, Introducint JSX

Inserting user input in JSX is safe, by default reactdom will escape any value in JSX before rendering, and all values will be converted to string form before rendering, which prevents XSS attacks.

Ii. Components and Props

All React the must act like pure functions with respect to their props.

The props in the component are read-only and cannot be modified

Iii. State and Lifecycle

State is similar to props, but it is private and fully controlled by the component itself. The state attribute only appears in class.

If you don't use something render() in, it shouldn ' t is in the state.

The only place to specify the This.state value is in constructor.

The state Update may be asynchronous

For better performance, react may invoke an update that batches multiple SetState (). Because This.props and this.state can be updated asynchronously, they cannot rely on their values to calculate the next state value. For example, the following may cause the counter update to fail:

// wrong  This . SetState ({  this. Props.increment,});

To solve this problem, you can use SetState () in the second method to pass in a function instead of an object to SetState (). The first parameter of the passed-in function is the current state, and the second parameter is the props before the update. So the above example can be rewritten as:

// Correct this. SetState ((prevstate, props) = ({  + props.increment});

Study Notes on official website

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.