File size: 1,625 Bytes
2485dd8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
import SocketWrapper from './SocketWrapper';
import {ThemeProvider} from '@mui/material/styles';
import theme from './theme';
import StreamingInterface from './StreamingInterface';
import CssBaseline from '@mui/material/CssBaseline';
import {createContext, useCallback, useState} from 'react';
import packageJson from '../package.json';
console.log(`Streaming React App version: ${packageJson?.version}`);
// Roboto font for mui ui library
// import '@fontsource/roboto/300.css';
// import '@fontsource/roboto/400.css';
// import '@fontsource/roboto/500.css';
// import '@fontsource/roboto/700.css';
export const AppResetKeyContext = createContext<(newKey: string) => void>(
() => {
throw new Error('AppResetKeyContext not initialized');
},
);
function App() {
return (
<ThemeProvider theme={theme}>
<CssBaseline />
<SocketWrapper>
<StreamingInterface />
</SocketWrapper>
</ThemeProvider>
);
}
function AppWrapper() {
const [appResetKey, setAppResetKey] = useState<string>('[initial value]');
const setAppResetKeyHandler = useCallback((newKey: string) => {
setAppResetKey((prev) => {
console.warn(
`Resetting the app with appResetKey: ${newKey}; prevKey: ${prev}`,
);
if (prev === newKey) {
console.error(
`The appResetKey was the same as the previous key, so the app will not reset.`,
);
}
return newKey;
});
}, []);
return (
<AppResetKeyContext.Provider value={setAppResetKeyHandler}>
<App key={appResetKey} />
</AppResetKeyContext.Provider>
);
}
export default AppWrapper;
|