The difference between prop and state in react

Source: Internet
Author: User
It is to be understood that props is a stream of data passed by a parent component to a child component that can be passed on to the descendant component. The state, however, represents the internal status of a component (which can be a parent component, a descendant component).
Changing the state of a component itself, semantically, is that the component has changed internally, and it may be necessary to re-render the component and the descendant components it contains.
The props is a parameter passed by the parent component that can be used to display the content, or a setting for the state of this component (some props can be used to set the component's States), not just the change in the inside of the component will cause a re-render, and the props passed by the parent component will change and execute.

Since both changes are likely to cause component re-rendering, it is only good to understand the meaning of pros and state to decide when to use props or state.


Official guidance has said, props initialization data, has been unchanged, the state is to change.


The state should include data that could be changed by the component's event handlers and trigger user interface updates, because the component itself cannot modify its own props.

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.