在React裏面有兩種組件, Class components(類組件) 和 Functional components(函數式組件).二者有明顯的區別,好比函數
什麼是Functional Componentscode
先看一段代碼:component
function Hello(props){ return <div>Hello {props.name}</div> }
這是一個函數式組件(Functional Component), 它和類組件(Class Component)最關鍵的區別就是: 函數式組件沒有state和一系列的鉤子函數,這也是函數式組件常常被用做無狀態組件的緣由io