Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create SSR example for GatsbyJS #154

Closed
jeroenransijn opened this issue Mar 8, 2018 · 3 comments
Closed

Create SSR example for GatsbyJS #154

jeroenransijn opened this issue Mar 8, 2018 · 3 comments

Comments

@jeroenransijn
Copy link
Contributor

I am using Gatsby for some of my prototypes and want to make SSR work. I will add an example as soon as I have done this.

@jeroenransijn
Copy link
Contributor Author

Create a file called gatsby-ssr.js in your project root with the following contents. Learn more about Gatsby SSR: https://www.gatsbyjs.org/docs/ssr-apis/

/* eslint-disable react/no-danger */
import React from 'react'
import { extractStyles } from 'evergreen-ui'

exports.onRenderBody = ({ setHeadComponents }) => {
  // Get the css and hydration script from Evergreen.
  const { css, hydrationScript } = extractStyles()

  // Takes an array of components as its first argument which are added to
  // the headComponents array which is passed to the html.js component.
  setHeadComponents([
    // We need a key here for Gatsby to stop complaining.
    <React.Fragment key="evergreen-ssr">
      <style id="evergreen-css" dangerouslySetInnerHTML={{ __html: css }} />
      {hydrationScript}
    </React.Fragment>,
  ])
}

@adrianwix
Copy link

Hi, how would this work for React-Static?

@stale
Copy link

stale bot commented Mar 11, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants