| 1 | /* eslint-disable react/jsx-pascal-case */ |
| 2 | |
| 3 | import React from 'react'; |
| 4 | import ReactDOM from 'react-dom'; |
| 5 | import ThemeContext from './shared/ThemeContext'; |
| 6 | |
| 7 | // Note: this is a semi-private API, but it's ok to use it |
| 8 | // if we never inspect the values, and only pass them through. |
| 9 | import {__RouterContext} from 'react-router'; |
| 10 | import {Provider} from 'react-redux'; |
| 11 | |
| 12 | // Pass through every context required by this tree. |
| 13 | // The context object is populated in src/modern/withLegacyRoot. |
| 14 | function Bridge({children, context}) { |
| 15 | return ( |
| 16 | <ThemeContext.Provider value={context.theme}> |
| 17 | <__RouterContext.Provider value={context.router}> |
| 18 | {/* |
| 19 | If we used the newer react-redux@7.x in the legacy/package.json, |
| 20 | we woud instead import {ReactReduxContext} from 'react-redux' |
| 21 | and render <ReactReduxContext.Provider value={context.reactRedux}>. |
| 22 | */} |
| 23 | <Provider store={context.reactRedux.store}>{children}</Provider> |
| 24 | </__RouterContext.Provider> |
| 25 | </ThemeContext.Provider> |
| 26 | ); |
| 27 | } |
| 28 | |
| 29 | export default function createLegacyRoot(container) { |
| 30 | return { |
| 31 | render(Component, props, context) { |
| 32 | ReactDOM.render( |
| 33 | <Bridge context={context}> |
| 34 | <Component {...props} /> |
| 35 | </Bridge>, |
| 36 | container |
| 37 | ); |
| 38 | }, |
| 39 | unmount() { |
| 40 | ReactDOM.unmountComponentAtNode(container); |
| 41 | }, |
| 42 | }; |
| 43 | } |