if the variable defined in this.state is changed, it will be re-render
if you don"t want it to render just how to change the value, do you need to write it outside the component
if the variable defined in this.state is changed, it will be re-render
if you don"t want it to render just how to change the value, do you need to write it outside the component
change the this.state page and it will be re-rendered. If you don't want to re-render, you can set the this.state. Change the variable to this. Variable to do operations; or, as mentioned upstairs, forcibly prevent it from rendering through the shouldComponentUpdate lifecycle.
your needs can be achieved through shouldComponentUpdate ()
.
change state
for render
. Your need is very strange.
react has a shouldComponent Update in its life cycle. If you judge in this life cycle function that the value in this.state is different from the previous value, you can return false to prevent react from render again
state change will trigger re-render, you had better not save state as a demand variable.
shouldComponentUpdate ()
you can change render
in state
this can only be limited within the cycle. State executes this.setState and render method is executed. If you don't want to, you can consider the condition mentioned above that render is not needed in the cycle. ShouldComponentUpdate must have a return value, otherwise an error will be reported that, return true executes render false and does not execute render. If you find it troublesome, you can consider the new method of naming components released in react version 16.
class Box extends React.PureComponent he can make some simple comparisons.
generally speaking, you can just hang it on this without this.state. But sometimes you have to hang some data that has nothing to do with rendering on state, such as getDerivedStateFromProps, so you can open a mutableArea object on state to hang variables. Directly modifying the properties of this object does not change itself, so it does not affect the rendering. It is more convenient than implementing shouldComponentUpdate.
Previous: Jvm memory problem
Next: Use and require in seajs
I d like to ask the bosses that if you want to use hbuilder to develop hybrid app, that has written ajax requests, you can request the obtained data in the local server environment. But after packaging, if you test it on the phone, you can t get the da...
< H2 > my question < H2 > Novice learning react has encountered a problem: the routing page cannot be displayed after clicking the < link > button. < H2 > my page < H2 > imitate a page of Wechat s public platform. The home page is login. Enter a ...
searched for a long time, but didn t seem to find ...
now you need to use echarts to implement a broken-line statistics function, as shown in figure displays the data for 10 days, and there may be data changes every hour of the day. If there is a change in the data, the inflection point will be displa...
html2canvas screenshots have all changed to the minimum font size. This problem has been found in chrome, and Firefox is normal. guess that it may be a compatibility problem caused by upgrading the plug-in some time ago, and there is no problem with t...
I am the front-end js,. I need to pass 4 parameters to Android and ios through OC, they do the sharing function, and then return to me whether the sharing is successful. how should it be implemented? there had better be no compatibility problems, now b...
Video playback is used in the project, but there are many front-end solutions for video players. I am not very clear about the mainstream solutions and their respective advantages and disadvantages. Can you give me a little list of better solutions so th...