Class components and migration

getDerivedStateFromError

Pure static boundary method returns state for fallback when a descendant throws during rendering.

Formal Syntax & Structure

react syntaxreact
static getDerivedStateFromError() { return {failed:true}; }

Working Example

Example Snippetreact
static getDerivedStateFromError() { return {failed:true}; }
React Reference