下面的代码有什么不同:
function MyComponent(){
const isPersistent = useRef(true)
// some more code...
}
代码是这样的:
let isPersistent = true
function MyComponent(){
// some more code...
}
我知道我通常会将useRef放在这些文件中.我从来不会用第二种方式,我只想知道为什么.这两个有什么不同?我知道我可以使用Ref来放置一个HTML元素.但如果不是这样,为什么第二个不是好的做法呢?