react 生命周期鈎子函數


實例化

  • constructor//構造函數:獲取props,然后state, 
  • componentWillMount//掛載之前,可修改setState
  • render//渲染真實dom
  • componentDidMount//第一次render后,僅一次,可setState

存在期

  • componentWillReceiveProps(nextprops)//父組件render時props更新時,不管props是否變化
  • shouldComponentUpdate//修改state后自動調用,默認返回true,false跳過后面的,少用
  • componentWillUpdate//修改state后的render之前自動調用,相似於CWM
  • render
  • componentDidUpdate//render后調用,萬不得已不要修改state死循環

銷毀期

  • componentWillUnmount//銷毀前

更改state 

  • this.setState((prevState,props)=>{
        return { }    
    }
    ,callback)

 setTimeout

let this.idInterval =setInterval()

clearInterval(this.idInterval)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM