_app.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import PropTypes from 'prop-types';
  2. import Head from 'next/head';
  3. import { CacheProvider } from '@emotion/react';
  4. import theme from '../src/theme';
  5. import createEmotionCache from '../src/createEmotionCache';
  6. import Layout from '../components/Layout'
  7. import * as React from 'react';
  8. import App from 'next/app';
  9. import { useState } from "react";
  10. import "@fontsource/roboto";
  11. import {
  12. CssBaseline, FormGroup, ToggleButton,
  13. } from "@mui/material";
  14. import { createTheme, ThemeProvider } from "@mui/material/styles";
  15. import Grid from "@material-ui/core/Grid";
  16. import { makeStyles } from "@material-ui/core";
  17. import { useTheme } from "@material-ui/core/styles";
  18. import useMediaQuery from "@material-ui/core/useMediaQuery";
  19. import dynamic from 'next/dynamic';
  20. import styled from '@emotion/styled';
  21. import ToggleColorMode from "../components/light_dark";
  22. const useStyles = makeStyles((theme) => ({
  23. root: {
  24. width: "100%",
  25. height: "100%",
  26. [theme.breakpoints.down("xs")]: {
  27. paddingTop: theme.spacing(2),
  28. },
  29. },
  30. }));
  31. const DynamicComponentWithNoSSR = <>Some JSX</>
  32. // Client-side cache, shared for the whole session of the user in the browser.
  33. const clientSideEmotionCache = createEmotionCache();
  34. function MyApp(props) {
  35. const classes = useStyles();
  36. const Theme = useTheme();
  37. const matches = useMediaQuery(theme.breakpoints.down("xs"));
  38. const { Component, emotionCache = clientSideEmotionCache, pageProps } = props;
  39. if (typeof window !== 'undefined') {
  40. console.log('You are on the browser')
  41. } else {
  42. console.log('You are on the server')
  43. }
  44. return (
  45. <>
  46. <CacheProvider value={emotionCache}>
  47. <Head>
  48. <meta name="viewport" content="initial-scale=1, width=device-width" />
  49. </Head>
  50. <Layout>
  51. <ThemeProvider theme={Theme}>
  52. {/* CssBaseline kickstart an elegant, consistent, and simple baseline to build upon. */}
  53. <CssBaseline />
  54. <Component {...pageProps} />
  55. <ToggleColorMode/>
  56. </ThemeProvider>
  57. </Layout>
  58. </CacheProvider>
  59. </>
  60. );
  61. }
  62. MyApp.propTypes = {
  63. Component: PropTypes.elementType.isRequired,
  64. emotionCache: PropTypes.object,
  65. pageProps: PropTypes.object.isRequired,
  66. };
  67. export default MyApp;