"REACT NATIVE Series Tutorial Four" three ways to refresh the component render (re-render)

Source: Internet
Author: User
This site article is Li Himi original, reproduced must be clearly noted:
Reprinted from "Black Rice gamedev Block" original link: http://www.himigame.com/react-native/2242.html

The development of the game should be very clear, "brush screen" is how important. In fact, the development of the application is also the case, when the data of the component is modified, how to update the component to present the latest data and effect is just as important.

So here Himi about three common ways: this.setstate () "most commonly used"

This is the primary method of triggering UI updates in the event handler and in the request callback function.

In general, SetState () always triggers a redraw unless conditional rendering logic is implemented in Shouldcomponentupdate (). If you use mutable objects, but you cannot implement this logic in Shouldcomponentupdate (), you can avoid unnecessary re-rendering by calling SetState () only when there is a difference between the new state and the previous state.

For example, the code snippet is as follows:

/table>
1 2 3 4 5 6 7 8 9-one for each of the ten, and the same. cons Tructor (props) {super (props); state = {           & nbsp;     myName: ' I am myname! ',};  }   Testfun () {     this. setState ({myName: ' component is refreshed '});}     Render () {         ...          < touchablehighlight            Underlaycolor = ' #4169e1 '            onpress = {this. testfun. Bind (
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.