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

2 years ago
  1. import { useState, useEffect } from 'react'
  2. // useEffect函数,作用就是为 react 函数组件提供副作用处理的
  3. /* count
  4. 1.导入 useEffect 函数
  5. 2.在函数组件中执行传入回调并且定义副作用
  6. 3.当通过修改状态更新组件时副作用也会不断执行 */
  7. function App () {
  8. const [count, setCount] = useState(0) // 0 是 count 的初始值
  9. useEffect(() => {
  10. // 定义副作用
  11. document.title = count
  12. })
  13. return (
  14. <div>
  15. <button onClick={() => setCount(count + 1)}>{count}</button>
  16. </div>
  17. )
  18. }
  19. export default App