Go ProSign in
The Beginner's Guide to React

The Beginner's Guide to React


    Stop Memory Leaks with componentWillUnmount Lifecycle Method in React

    Kent C. DoddsKent C. Dodds

    In this lesson, we have a stopwatch component that will update the time since it was run in milliseconds. The problem is, if you unmount the component, there is a memory leak because the interval that is set when you start and the timer is not stopped. React provides the componentWillUnmount lifecycle method as an opportunity to clear anything that needs to be cleared when the component is unmounted or removed from the DOM.

    You must be a Member to view code