1. useState 功能:讓靜態(tài)組件可以使用狀態(tài)state,實現(xiàn)類似于class類組件this.state this.setState()功能,只要state發(fā)生改變,就重新調用組件函數(shù),重新渲染render。
?2. useEffect 功能:讓靜態(tài)組件可以使用生命周期方法,實現(xiàn)類似于class類組件 componentDidMount、componentDidUpdate、componentWillUnmount功能
?3. useCallback 功能:用于靜態(tài)組件優(yōu)化,可以緩存給子組件傳遞的函數(shù)
?4. useMemo 功能:用于靜態(tài)組件優(yōu)化,可以緩存函數(shù)執(zhí)行完返回的函數(shù),與userCallback功能類似
?5. useReducer 功能:讓靜態(tài)組件可以使用state,實現(xiàn)方式和useState不同,通過發(fā)送dispatch(action)-->到-->reducer--->返回新state值,重新調用組件函數(shù),重新渲染render
? ? ? ? ? ? ? ? ? ? ? 另一個功能結合useContext實現(xiàn) redux 數(shù)據(jù)流管理
?6. useContext 功能:讓實現(xiàn)靜態(tài)組件跨級通信,簡單好用
?7. useReducer+useContext實現(xiàn)redux,需要自己封裝combineReducers、dispatch攔截函數(shù)等