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

[minor][feat] add custom renderer support for SSR. #1865

Merged

Conversation

ashuverma
Copy link
Contributor

This is to support use cases like css in js e.g. Rendering Styled Components on server

e.g. in server entry (server.js)

import {ServerStyleSheet} from "styled-components";
import ReactDOM from "react-dom/server";

export default {
renderer(element, options) {
   const sheet = new ServerStyleSheet();
   try {
      const html = ReactDOMServer.renderToString(.  // This can be renderToNodeStream or Static markup/stream depending on option. 
                              sheet.collectStyles(element)
       );
      const styleTags = sheet.getStyleTags(); 

      return styleTags + html;
    } catch (error) {
        console.log(error);
    }
}

This is to support use cases like css in js e.g. Rendering Styled Components on server
@ashuverma
Copy link
Contributor Author

@divyakarippath @jchip

@divyakarippath divyakarippath merged commit 31dcc0d into electrode-io:master Dec 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants