import React from 'react'; import ReactDOM from 'react-dom'; import {cache} from '@emotion/css'; // eslint-disable-line emotion/no-vanilla import {CacheProvider, ThemeProvider} from '@emotion/react'; // This is needed to set "speedy" = false (for percy) import {loadPreferencesState} from 'app/actionCreators/preferences'; import ConfigStore from 'app/stores/configStore'; import GlobalStyles from 'app/styles/global'; import {Config} from 'app/types'; import {darkTheme, lightTheme, Theme} from 'app/utils/theme'; import withConfig from 'app/utils/withConfig'; type Props = { config: Config; }; type State = { theme: Theme; }; class Main extends React.Component { state = { theme: this.themeName === 'dark' ? darkTheme : lightTheme, }; componentDidMount() { loadPreferencesState(); } componentDidUpdate(prevProps: Props) { const {config} = this.props; if (config.theme !== prevProps.config.theme) { // eslint-disable-next-line this.setState({ theme: config.theme === 'dark' ? darkTheme : lightTheme, }); } } get themeName() { return ConfigStore.get('theme'); } render() { return ( {this.props.children} {ReactDOM.createPortal( , document.head )} ); } } export default withConfig(Main);