Lifecycle and Effects Working with the useEffect hook

This lesson is available for PRO members or as a single course purchase. Sign-in and choose a plan below.

Lifecycle with Class Components

class Lifecycle extends React.Component {
  componentDidMount() {
    // Initialize

  componentDidUpdate() {
    // Updated

  componentWillUnmount() {
    // Removed

Lifecycle with useEffect

function Lifecycle() {

  const [count] = useState(0);

  useEffect(() => {
    console.log('count updated!')

    return () => console.log('destroyed!')

  }, [count]);



Implement a CountdownTimer component that implements useState() and useEffect() in conjunction with setInterval to handle the timer. Make sure you use the useEffect() hook to call clearTimeout() when the component is destroyed.


Ask questions via GitHub below OR chat on Slack #questions