Hooks #

useState #

useEffect #

useRef #

Quick demonstration of why hooks are cool:

Class-based

componentDidMount(){
    setupSubscriptions()
    getData()
}

componentDidUnmount(){
    clearSubscriptions()
}

here, we are forced to group functions by lifecycle methods, not by functionality

Using hooks, however, this becomes


useEffect(getData)
useEffect(setupSubscriptions, clearSubscriptions)

Allowing us to group related functionality