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)
1.1 General marking A general tag consists of an ...
Install the required environment 1. gcc installat...
The code under the easyui framework is as follows...
This article example shares the specific code of ...
Mirroring is also one of the core components of D...
Preface 1. Debounce: After a high-frequency event...
Yesterday, I wrote a blog about the circular prog...
Table of contents 1. Array.at() 2. Array.copyWith...
Reminder: Whether it is planning, designing, or de...
This article example shares the specific code of ...
This article shares the specific code of jQuery t...
KVM stands for Kernel-based Virtual Machine, whic...
Preparation Windows Server 2008 R2 Enterprise (2....
Table of contents Preface Virtual DOM What is Vir...
This article shares the specific code for JavaScr...