Class components and migration

componentDidUpdate

Committed update hook receives previous props/state and optional snapshot. Not called for initial mount; guard updates.

Formal Syntax & Structure

react syntaxreact
componentDidUpdate(prevProps) { if (prevProps.room !== this.props.room) { this.disconnect(); this.connect(); } }

Working Example

Example Snippetreact
componentDidUpdate(prevProps) { if (prevProps.room !== this.props.room) { this.disconnect(); this.connect(); } }
React Reference