Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

configuring styled component to support ssr and hydration

import Document from "next/document";
import { ServerStyleSheet } from "styled-components";

export default class MyDocument extends Document {
  static async getInitialProps(ctx) {
    const sheet = new ServerStyleSheet();
    const originalRenderPage = ctx.renderPage;

    try {
      ctx.renderPage = () =>
        originalRenderPage({
          enhanceApp: (App) => (props) =>
            sheet.collectStyles(<App {...props} />),
        });

      const initialProps = await Document.getInitialProps(ctx);
      return {
        ...initialProps,
        styles: (
          <>
            {initialProps.styles}
            {sheet.getStyleElement()}
          </>
        ),
      };
    } finally {
      sheet.seal();
    }
  }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: jquery show only first elements of table 
Javascript :: transform js to typescript 
Javascript :: Execercise for loop 
Javascript :: with jquery Make a style menu that displays paragraphs and hides them according to the style of the slides 
Javascript :: toggling individual item using map in react 
Javascript :: angular date passed to donet care is a day less 
Javascript :: Why is node creating multiple server in cpanel 
Javascript :: svelte function at interval 
Javascript :: js cyclic motion based on cosine 
Javascript :: searchable 
Javascript :: plumsail on change event value 
Javascript :: (state.isLoggedIn = function() {return false}) react redux 
Javascript :: get number value from input e.target.value instead of string 
Javascript :: javascript array includes time complexity 
Javascript :: javascript assigning index number to row in table 
Javascript :: angularjs checking array of objects 
Javascript :: ! function in javascript 
Javascript :: Angular js Directive to Fire "click" event on pressing enter key on ANY element 
Javascript :: how to use recursive function to select the parent in a tree array using angulat ui tree 
Javascript :: How to add the items from a array of JSON objects to an array in Reducer 
Javascript :: async mutex 
Javascript :: Store input values in array javascript 
Javascript :: vscode search shortcut 
Javascript :: javascript encriment +1 
Javascript :: Modules: Remember All Strings Will Now Have a Property After You Use Require 
Javascript :: phaser asteroid movement 
Javascript :: Create Nodejs logger that does not replace file when app/server restarts 
Javascript :: javascript download save files in folder 
Javascript :: Object.entries() To Use For Of On JSON 
Javascript :: Create A JSON From 2D Array Example 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =