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)
In enterprises, database high availability has al...
1. Installation package preparation VMware-player...
This article example shares the specific code of ...
As a lightweight open source database, MySQL is w...
The questions encountered in Baidu interviews nee...
This article uses an example to describe how MySQ...
Preface We all know that MySQL uses server-id to ...
Knowledge point 1: Set the base URL of the web pa...
Table of contents 1- Error details 2-Single Solut...
Table of contents need: Main points: According to...
When applying docker containers, we often mount t...
<br /> In the first and second parts, we int...
Select or create a subscription message template ...
webkit scrollbar style reset 1. The scrollbar con...
1. First, use springboot to build a simple dubbo ...