1. /**
    
  2.  * Copyright (c) Meta Platforms, Inc. and affiliates.
    
  3.  *
    
  4.  * This source code is licensed under the MIT license found in the
    
  5.  * LICENSE file in the root directory of this source tree.
    
  6.  *
    
  7.  * @flow
    
  8.  */
    
  9. 
    
  10. import * as React from 'react';
    
  11. import {Fragment, useContext, useEffect, useState} from 'react';
    
  12. import {unstable_batchedUpdates as batchedUpdates} from 'react-dom';
    
  13. import {ModalDialogContext} from './ModalDialog';
    
  14. import {StoreContext} from './context';
    
  15. import {UNSUPPORTED_VERSION_URL} from '../constants';
    
  16. 
    
  17. import styles from './UnsupportedVersionDialog.css';
    
  18. 
    
  19. type DAILOG_STATE = 'dialog-not-shown' | 'show-dialog' | 'dialog-shown';
    
  20. 
    
  21. export default function UnsupportedVersionDialog(_: {}): null {
    
  22.   const {dispatch} = useContext(ModalDialogContext);
    
  23.   const store = useContext(StoreContext);
    
  24.   const [state, setState] = useState<DAILOG_STATE>('dialog-not-shown');
    
  25. 
    
  26.   useEffect(() => {
    
  27.     if (state === 'dialog-not-shown') {
    
  28.       const showDialog = () => {
    
  29.         batchedUpdates(() => {
    
  30.           setState('show-dialog');
    
  31.           dispatch({
    
  32.             canBeDismissed: true,
    
  33.             id: 'UnsupportedVersionDialog',
    
  34.             type: 'SHOW',
    
  35.             content: <DialogContent />,
    
  36.           });
    
  37.         });
    
  38.       };
    
  39. 
    
  40.       if (store.unsupportedRendererVersionDetected) {
    
  41.         showDialog();
    
  42.       } else {
    
  43.         store.addListener('unsupportedRendererVersionDetected', showDialog);
    
  44.         return () => {
    
  45.           store.removeListener(
    
  46.             'unsupportedRendererVersionDetected',
    
  47.             showDialog,
    
  48.           );
    
  49.         };
    
  50.       }
    
  51.     }
    
  52.   }, [state, store]);
    
  53. 
    
  54.   return null;
    
  55. }
    
  56. 
    
  57. function DialogContent(_: {}) {
    
  58.   return (
    
  59.     <Fragment>
    
  60.       <div className={styles.Row}>
    
  61.         <div>
    
  62.           <div className={styles.Title}>Unsupported React version detected</div>
    
  63.           <p>
    
  64.             This version of React DevTools supports React DOM v15+ and React
    
  65.             Native v61+.
    
  66.           </p>
    
  67.           <p>
    
  68.             In order to use DevTools with an older version of React, you'll need
    
  69.             to{' '}
    
  70.             <a
    
  71.               className={styles.ReleaseNotesLink}
    
  72.               target="_blank"
    
  73.               rel="noopener noreferrer"
    
  74.               href={UNSUPPORTED_VERSION_URL}>
    
  75.               install an older version of the extension
    
  76.             </a>
    
  77.             .
    
  78.           </p>
    
  79.         </div>
    
  80.       </div>
    
  81.     </Fragment>
    
  82.   );
    
  83. }