/*
* @Author: Spring
* @LastEditors: Aidam_Bo
* @LastEditTime: 2023-01-09 22:22:30
*/
import React, {useEffect,useState,useRef} from 'react'
export default function UseRefSave() {
//useState也是记忆函数,记住状态
const [count, setcount] = useState(0);
//var mycount=0;
var mycount=useRef(0);
return (
<div>
<button onClick={()=>{
setcount(count + 1)
mycount.current++
}}>点击</button>
{count}-{mycount.current}
</div>
)
}
React-hooks-useRef:保存引用值、保存变量
最新推荐文章于 2024-02-26 21:13:04 发布