| 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 {ModalDialogContext} from './ModalDialog'; |
| 13 | import {StoreContext} from './context'; |
| 14 | import {UNSUPPORTED_VERSION_URL} from '../constants'; |
| 15 | |
| 16 | import styles from './UnsupportedVersionDialog.css'; |
| 17 | |
| 18 | type DAILOG_STATE = 'dialog-not-shown' | 'show-dialog' | 'dialog-shown'; |
| 19 | |
| 20 | export default function UnsupportedVersionDialog(_: {}): null { |
| 21 | const {dispatch} = useContext(ModalDialogContext); |
| 22 | const store = useContext(StoreContext); |
| 23 | const [state, setState] = useState<DAILOG_STATE>('dialog-not-shown'); |
| 24 | |
| 25 | useEffect(() => { |
| 26 | if (state === 'dialog-not-shown') { |
| 27 | const showDialog = () => { |
| 28 | setState('show-dialog'); |
| 29 | dispatch({ |
| 30 | canBeDismissed: true, |
| 31 | id: 'UnsupportedVersionDialog', |
| 32 | type: 'SHOW', |
| 33 | content: <DialogContent />, |
| 34 | }); |
| 35 | }; |
| 36 | |
| 37 | if (store.unsupportedRendererVersionDetected) { |
| 38 | showDialog(); |
| 39 | } else { |
| 40 | store.addListener('unsupportedRendererVersionDetected', showDialog); |
| 41 | return () => { |
| 42 | store.removeListener( |
| 43 | 'unsupportedRendererVersionDetected', |
| 44 | showDialog, |
| 45 | ); |
| 46 | }; |
| 47 | } |
| 48 | } |
| 49 | }, [state, store]); |
| 50 | |
| 51 | return null; |
| 52 | } |
| 53 | |
| 54 | function DialogContent(_: {}) { |
| 55 | return ( |
| 56 | <Fragment> |
| 57 | <div className={styles.Row}> |
| 58 | <div> |
| 59 | <div className={styles.Title}>Unsupported React version detected</div> |
| 60 | <p> |
| 61 | This version of React DevTools supports React DOM v15+ and React |
| 62 | Native v61+. |
| 63 | </p> |
| 64 | <p> |
| 65 | In order to use DevTools with an older version of React, you'll need |
| 66 | to{' '} |
| 67 | <a |
| 68 | className={styles.ReleaseNotesLink} |
| 69 | target="_blank" |
| 70 | rel="noopener noreferrer" |
| 71 | href={UNSUPPORTED_VERSION_URL}> |
| 72 | install an older version of the extension |
| 73 | </a> |
| 74 | . |
| 75 | </p> |
| 76 | </div> |
| 77 | </div> |
| 78 | </Fragment> |
| 79 | ); |
| 80 | } |