React is changing the game for streaming apps with the Activity component
Blog post from Mux
Video streaming applications often face challenges with state preservation, particularly when users navigate between multiple views such as video players and notes. React exacerbates this issue by unmounting components when they are hidden, which resets their state. With the introduction of React 19.2's new <Activity> component, developers can address this problem by keeping components in the DOM while toggling their visibility, thus preserving their state. This component accepts a `mode` prop with "visible" or "hidden" values, ensuring that components like video players can maintain their playback position even when not on display. However, while this preserves state, it may allow media to continue playing in the background unless additional logic is applied. A more refined solution combines <Activity> with the useLayoutEffect hook to pause playback when the component is hidden, ensuring a seamless user experience where playback resumes exactly where it left off upon returning. This approach not only enhances user satisfaction in video applications but can also be applied to forms, data tables, and music players to maintain state across navigations.