React Learning Essays

Source: Internet
Author: User

The 1.render should be a pure function, meaning that each time the same input is given, the same output should be returned, and there should be no behavior that modifies the state or interaction, which is passed on to the logic.

2. Components should follow the minimize state principle, that is, to make most of the components stateless, so as to reduce complexity, the only thing that these stateless components need to be concerned about is rendering data, their outer layer plus a state component, the outer component handles events and logic, Modify the state. These stateless subcomponents are just as good as rendering the data based on the incoming props.

3.DOM operation, in most cases we do not need to manipulate the DOM to modify the UI, but rather use setstate to do it, but in some cases we have to access the real DOM, such as the user input component in the real DOM entered a value, Then we will have access to the real DOM node through refs.

Specifically, a REFS property is set on the node and then the DOM node is obtained through THIS.REFS.NAME.

As an example:

<input type= "text" refs= "Realdom"/>

<button onclick={Callback}/>

Then the callback of this button can get the input value.

Callback () {

Let value = This.refs.realdom.value

Let Statechange=value

You can also change the state to re-render the component

This.setstate (

{StateChange}, () =>{this.refs.readom.value= "";}

);

}


Related Article

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.