About props and State (REACT)

Source: Internet
Author: User

React data models are classified into common data and private data. Common data can be transferred between components, and private data is private to the current component. A total of data is called using a props object in react. It contains all attribute names and attribute values of the tag. The props object has three features, one-way mobility, display transmission, and read-only. Unidirectional mobility means that the react data can only be transmitted from the parent component to the child component, but not from the child component to the parent component. Display transmission means that attributes must be explicitly assigned to the child component, data can be transmitted to sub-components. Read-only means that props data is read-only. After the data is modified, the original data model is not changed, but a new data model is generated, load the new data model to the original parent element to complete data transmission and component status changes. Private Data is private to components and is called using State objects in react. The State data model can be conveniently updated without affecting other components.

It should be understood that props is a data stream that the parent component passes to the child component. This data stream can be passed to the child component all the time. The State represents the internal state of a component (which can be a parent component or a child component ). To change the state of a component, the component is changed in semantics and may need to be re-rendered for this component and its child components. Props is a parameter passed by the parent component. It can be used to display content or set the component's own status (some props can be used to set the component's State ), not only changes in the internal state of the component will lead to re-rendering, but also changes in the props passed by the parent component.

Since both changes may cause component re-rendering, only by understanding the meaning of props and state can we determine when to use props or state.

About props and State (REACT)

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.