import * as React from 'react';
import {Fragment, useContext, useEffect} from 'react';
import {BridgeContext} from './context';
import {ModalDialogContext} from './ModalDialog';
import styles from './WarnIfLegacyBackendDetected.css';
export default function WarnIfLegacyBackendDetected(_: {}): null {
const bridge = useContext(BridgeContext);
const {dispatch} = useContext(ModalDialogContext);
useEffect(() => {
let unlisten: $FlowFixMe = bridge.wall.listen(message => {
switch (message.type) {
case 'call':
case 'event':
case 'many-events':
dispatch({
canBeDismissed: false,
id: 'WarnIfLegacyBackendDetected',
type: 'SHOW',
title: 'DevTools v4 is incompatible with this version of React',
content: <InvalidBackendDetected />,
});
if (typeof unlisten === 'function') {
unlisten();
unlisten = null;
}
break;
default:
break;
}
switch (message.event) {
case 'isBackendStorageAPISupported':
case 'isNativeStyleEditorSupported':
case 'operations':
case 'overrideComponentFilters':
if (typeof unlisten === 'function') {
unlisten();
unlisten = null;
}
break;
default:
break;
}
});
return () => {
if (typeof unlisten === 'function') {
unlisten();
unlisten = null;
}
};
}, [bridge, dispatch]);
return null;
}
function InvalidBackendDetected(_: {}) {
return (
<Fragment>
<p>Either upgrade React or install React DevTools v3:</p>
<code className={styles.Command}>npm install -d react-devtools@^3</code>
</Fragment>
);
}