import React, { useState } from 'react' import { Button } from '@alifd/next'; function index() { //只要useState的值发生变化,就机会一直到debugger这,所以total会一直清空,这就是useState存在的道理 debugger; const [mshow, setmshow] = useState(false); let total = 100; let get1 = () => { alert(mshow); alert(total) } let set1 = () => { total = 0; setmshow(!mshow); } return ( <div> <Button onClick={get1}>读取</Button> <Button onClick={set1}>设置</Button> </div> ) } export default index