You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
675 B
25 lines
675 B
import { useState, useEffect } from 'react'
|
|
|
|
// useEffect函数,作用就是为 react 函数组件提供副作用处理的
|
|
|
|
/* 在修改数据之后,把 count 值放在页面标题中
|
|
1.导入 useEffect 函数
|
|
2.在函数组件中执行,传入回调,并且定义副作用
|
|
3.当通过修改状态更新组件时,副作用也会不断执行 */
|
|
|
|
function App () {
|
|
const [count, setCount] = useState(0) // 0 是 count 的初始值
|
|
|
|
useEffect(() => {
|
|
// 定义副作用
|
|
document.title = count
|
|
})
|
|
|
|
return (
|
|
<div>
|
|
<button onClick={() => setCount(count + 1)}>{count}</button>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default App
|