Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

makestyle server side rendering

import React from "react";
import Document, { Html, Head, Main, NextScript } from "next/document";
import { ServerStyleSheets } from "@material-ui/core/styles";

class MyDocument extends Document {
  static async getInitialProps(ctx) {
    const sheets = new ServerStyleSheets();
    const originalRenderPage = ctx.renderPage;

    ctx.renderPage = () =>
      originalRenderPage({
        enhanceApp: (App) => (props) => sheets.collect(<App {...props} />)
      });

    const initialProps = await Document.getInitialProps(ctx);

    return {
      ...initialProps,
      // Styles fragment is rendered after the app and page rendering finish.
      styles: [
        ...React.Children.toArray(initialProps.styles),
        sheets.getStyleElement()
      ]
    };
  }

  render() {
    return (
      <Html lang="en">
        <Head />
        <body>
          <Main />
          <NextScript />
        </body>
      </Html>
    );
  }
}

export default MyDocument;
Comment

PREVIOUS NEXT
Code Example
Javascript :: display toggle jquery for few seconds 
Javascript :: discord.js anonymous channel 
Javascript :: getelementbyid without the <script 
Javascript :: update mongoose 
Javascript :: javascript events reference 
Javascript :: angular table lazy loading 
Javascript :: lieke==1 
Javascript :: how to get file tree of specific folder in node js 
Javascript :: how to filter data in javascript object 
Javascript :: get members of a group graph pnp js 
Javascript :: how to change a react link icon when you send the link as message in whatsapp 
Javascript :: likedislike mangodb 
Javascript :: es6 parameter destructuring nested object 
Javascript :: form react js 
Javascript :: alpiee js hide amother button click 
Javascript :: freecodecamp Drop it 
Javascript :: firebase iterate object 
Javascript :: javascript split domain 
Javascript :: UnhandledPromiseRejectionWarning: SequelizeDatabaseError: type "enum" already exists 
Javascript :: check variable is array or not in javascript 
Javascript :: modal in react 
Javascript :: navigation with load page in angluar 
Javascript :: faster filter array in JavaScript 
Javascript :: object.keys map 
Javascript :: javascript class prototype 
Javascript :: xstate vu.js 
Javascript :: error number:-1,state:0,class:20 
Javascript :: nuxt auth no provider 
Javascript :: random number javascript 
Javascript :: How can I use a regex variable in a query for MongoDB 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =