An effect synchronizes a component with an external system. React calls cleanup when dependencies change or the component unmounts.
The demo shows channel A disconnecting before B connects on a timeline. Do not copy values into state with an effect when they can be calculated during render.
When to use
Use it to synchronize subscriptions, sockets, timers, and other external resources.