React Run phase

Source: Internet
Author: User

    1. Functions that can be used in a run
      Componentwillreceiveprops: The parent component modifies the property trigger and can modify the new property to modify the state. Literally, the component is going to receive the attribute, and the time that the function triggers is when the component's properties are about to change, but it's important to note that it triggers before the component is going to change, such as when the parent component modifies the properties of the subassembly, which triggers the function before the change actually occurs, and says, Give developers a chance to deal with this property, developers can compare new attributes and old attributes, and modify properties and states, so that we can actually be transferred to the component before the property is processed, it is possible to change some state, it is possible to modify the property itself.

      Shouldcomponentupdate: Returning false will prevent the render call. The English meaning is whether the component needs to be updated, that is, react will ask the developer, whether the component needs to be updated, sometimes the state changes, the component may not need to update, just update some data, do not need to update the displayed content, this time, this function will need to return false, The next three functions in the run are related to render, and if the function returns FALSE, the process will be interrupted directly, and the subsequent three functions will not be executed. It is important to note that most of the time, we do not need to use this function, only after you really find the bottleneck of the project, and then modify it as needed, because improper use of this function will lead to many unpredictable problems.

      Componentwillupdate: The property and state cannot be modified. is performed prior to render

      Render: Only This.props and this.state are accessible, with only one top-level component, which does not allow modification of state and DOM output.

      Componentdidupdate: You can modify the DOM

    2. The firing sequence in the run.
      This is an example of what input is and what the page content will become Hello
      <! DOCTYPE html>

      Change the code to see the order of the output properties.

      <! DOCTYPE html>

      When there is no input, only the render is triggered,

      Each time the content is entered, it is triggered once.

      <! DOCTYPE html>

      Look at the output, where an object is output

React Run phase

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: 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.