Problem description:const [textList, setTextList] = useState(original array); setTextList(new array); When modifying the original array, if the original array is a deep array (more than one layer), using setTextList to modify it will not trigger a page refresh Cause Analysis:This involves the knowledge of mutable objects and immutable objects. In Vue and React, if you update a mutable object, it may cause the view to update. This is because Vue and React are shallow listeners by default, and only listen to the first layer of data. Changes in the inner layer data will not be monitored. Solution:My solution here is to first make a deep copy of the original array, assign it to the new array, then modify the new array and pass the modified new array in, which will cause the view to update. var lists = textList.concat(); lists.splice(index, 1); setTextList(lists); Supplement: In react, useState updates do not render components when hooks are used When using react and writing components like the one shown in the figure, I found a critical problem. When I choose to write it with class, it is easy to update the rendering through the component. Now that the problem has been solved, let's go back and see what happened. . . The above is the detailed solution to the problem that the setState update page of react pure function component does not refresh. For more information about the react useState page not refreshing, please pay attention to other related articles on 123WORDPRESS.COM! You may also be interested in:
|
<<: VMware vsphere 6.5 installation tutorial (picture and text)
Table of contents 1. Parent component passes valu...
Table of contents First, let's talk about the...
Table of contents Why do we need partitions? Part...
Introduction Binlog logs, that is, binary log fil...
MySQL partitioning is helpful for managing very l...
Table of contents 1. Create a Hadoop directory in...
1. Install Docker yum -y install docker-io The &q...
30 free high-quality English ribbon fonts for down...
Simple use of Vue bus Scenario description: Compo...
This article shares the specific code of the vue-...
Table of contents history pushState() Method push...
Database application is an indispensable part of ...
Overview Indexing is a skill that must be mastere...
In addition to B-Tree indexes, MySQL also provide...
Preface The blogger uses the idea IDE. Because th...