1,保存变量永远不丢失
import React, { useState,useRef } from 'react'
export default function App() {
const [count,setcount] = useState(0)
var mycount = useRef(0)//保存变量永远不丢失--useRef用的是闭包原理
return(
<div>
<button onClick={()=>{
setcount(count + 1)
mycount.current++
}}>add</button>
{count} - {mycount.current}
</div>
)
}
2 绑定在dom上或组件上,无论实现dom原生节点访问还是组件通信都可以


![%00截断 [GKCTF 2020]cve版签到](https://img-blog.csdnimg.cn/direct/05c1c5337e5d493eb36872412d192e81.png)

















