_app.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. const toggleTheme = dynamic(() => import("../components/light_dark"),{
  22. ssr:false
  23. });
  24. const useStyles = makeStyles((theme) => ({
  25. root: {
  26. width: "100%",
  27. height: "100%",
  28. [theme.breakpoints.down("xs")]: {
  29. paddingTop: theme.spacing(2),
  30. },
  31. },
  32. }));
  33. const DynamicComponentWithNoSSR = <>Some JSX</>
  34. // Client-side cache, shared for the whole session of the user in the browser.
  35. const clientSideEmotionCache = createEmotionCache();
  36. function MyApp(props) {
  37. const classes = useStyles();
  38. const Theme = useTheme();
  39. const matches = useMediaQuery(theme.breakpoints.down("xs"));
  40. const { Component, emotionCache = clientSideEmotionCache, pageProps } = props;
  41. if (typeof window !== 'undefined') {
  42. console.log('You are on the browser')
  43. } else {
  44. console.log('You are on the server')
  45. }
  46. return (
  47. <>
  48. <CacheProvider value={emotionCache}>
  49. <Head>
  50. <meta name="viewport" content="initial-scale=1, width=device-width" />
  51. </Head>
  52. <Layout>
  53. <ThemeProvider theme={Theme}>
  54. {/* CssBaseline kickstart an elegant, consistent, and simple baseline to build upon. */}
  55. <CssBaseline />
  56. <Component {...pageProps} />
  57. <toggleTheme/>
  58. </ThemeProvider>
  59. </Layout>
  60. </CacheProvider>
  61. </>
  62. );
  63. }
  64. MyApp.propTypes = {
  65. Component: PropTypes.elementType.isRequired,
  66. emotionCache: PropTypes.object,
  67. pageProps: PropTypes.object.isRequired,
  68. };
  69. export default MyApp;