Class components and migration
getDerivedStateFromProps
Rare render-phase adjustment; returns a partial state object or null. Keep pure and avoid redundant derived state.
Formal Syntax & Structure
react syntaxreact
static getDerivedStateFromProps(props, state) { return props.id !== state.id ? {id: props.id, draft: ""} : null; }Working Example
Example Snippetreact
static getDerivedStateFromProps(props, state) { return props.id !== state.id ? {id: props.id, draft: ""} : null; }