diff --git a/packages/react-devtools-shell/src/app/InspectableElements/Contexts.js b/packages/react-devtools-shell/src/app/InspectableElements/Contexts.js index 256cd908518f2..ace7af6d55d3b 100644 --- a/packages/react-devtools-shell/src/app/InspectableElements/Contexts.js +++ b/packages/react-devtools-shell/src/app/InspectableElements/Contexts.js @@ -273,15 +273,46 @@ class ModernClassContextConsumerWithUpdates extends Component { } } +type LegacyContextState = { + supportsLegacyContext: boolean, +}; +class LegacyContext extends React.Component { + state: LegacyContextState = {supportsLegacyContext: true}; + + static getDerivedStateFromError(error: any): LegacyContextState { + return {supportsLegacyContext: false}; + } + + componentDidCatch(error: any, info: any) { + console.info( + 'Assuming legacy context is not supported in this React version due to: ', + error, + info, + ); + } + + render(): React.Node { + if (!this.state.supportsLegacyContext) { + return

This version of React does not support legacy context.

; + } + + return ( + + + + + + + ); + } +} + export default function Contexts(): React.Node { return (

Contexts