Effect Hook

Effect Hook: 
函数组件执行副作用操作

函数组件+hook
import React,{useEffect,useState} from "react"

export default function Hook(){
     //状态:(声明)
    const [count,setCount] = useState(1)

    // 函数:(功能实现)
    function Add(){
       setCount(count+1)
    }
    // 挂载:(显示):挂载+更新+销毁
    useEffect(()=>{
         document.title = 点击了`${count+1}`次
     })
    // 渲染:(render)
    return(
      <div>
        <h1>this.count</h1>
        <button onClick={()=>{Add}}></button>
     </div>
   )
}
posted @ 2022-11-18 12:43  Cherishe  阅读(14)  评论(0)    收藏  举报