React Hooks
2023年2月22日小于 1 分钟reactreacthooks
useState
为函数组件引入可记忆的状态
import React, { useState } from 'react'
const Home: React.FC = props => {
const [count, setCount] = useState<number>(0)
const handleClick = () => {
setCount(count + 1)
}
return (
<>
<h1>Count:{count}</h1>
<button onClick={handleClick}>点击加一</button>
</>
)
}
export default Home