import { Button } from 'react-bootstrap';
import React ,{useState, useLayoutEffect}from 'react'
//使用useEffect,每次都会渲染这个0
const Count = () => {
const [count,setCount]=useState(10)
useLayoutEffect(() => {
if(count===0){
setCount(Math.random())
}
}, [count])
return (
<div>
<h2>数字:{count}</h2>
<Button onClick={e=>setCount(0)}>修改数字</Button>
</div>
)
}
export default Count