源码
import React, {useState} from "react";
function HiHooks() {
const [count, setCount] = useState(20)
let myUseState = useState(100)
let myCount = myUseState[0]
let mySetCount = myUseState[1]
return (
<div>
<h3>初始值为 useState(20) 括号内的值</h3>
<h3>{count}</h3>
<button onClick={() => setCount(count + 1)}>
count++
</button>
<hr/>
<h1>如果不用es6的解构</h1>
<h3>初始值为 let myUseState = useState(100) 括号内的值</h3>
<h3>{myCount}</h3>
<button onClick={() => {
mySetCount(myCount + 1)
}}>
不用es6的解构
</button>
</div>
)
}
export default HiHooks