How to quickly get and render the state value in react (synchronized with the interface), how to delay the acquisition and rendering of the state value?

1. In most scenarios, the state value changes, and it is hoped that the page will be updated and rendered immediately, so how to do it?
Answer: 1) When setting the state value, return it through a function
insert image description here
2) Realize caching through useRef

 const filepath_=useRef<any>()
 filepath_.current=data
 //这种方式比setState快
 console.log("文件夹路径",filepath_);

2. In some scenarios, it is desirable to delay obtaining the status value A. For example, if there is an API whose response is slow to render, the execution of the API may cause the API to return no value if the status value is judged too early (for example, there are too many openlayers map elements, rendering Too slow, slower than getting the state value).
Solution: 1) Set the timer (not recommended)
2) Set the status value in nextTick, and call the function of logic judgment execution in nextTick.
3) Then call the logic judgment execution function in an asynchronous function (backend interface function).

Guess you like

Origin blog.csdn.net/qq_37967853/article/details/129443625