How to use the react-helmet.renderStatic function in react-helmet

To help you get started, we’ve selected a few react-helmet examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sysgears / apollo-universal-starter-kit / src / server / middleware / website.jsx View on Github external
await getDataFromTree(element);

  if (context.pageNotFound === true) {
    res.status(404);
  } else {
    res.status(200);
  }

  const sheet = new ServerStyleSheet();
  const html = ReactDOMServer.renderToString(sheet.collectStyles(element));
  const css = sheet
    .getStyleElement()
    .concat(stylesheets)
    .map((el, idx) => React.cloneElement(el, { key: idx }));
  const helmet = Helmet.renderStatic(); // Avoid memory leak while tracking mounted instances

  if (context.url) {
    res.writeHead(301, { Location: context.url });
    res.end();
  } else {
    if (__DEV__ || !assetMap) {
      assetMap = JSON.parse(fs.readFileSync(path.join(spinConfig.frontendBuildDir, 'web', 'assets.json')));
    }

    const apolloState = Object.assign({}, cache.extract());

    const token = req.universalCookies.get('x-token') ? req.universalCookies.get('x-token') : null;
    const refreshToken = req.universalCookies.get('x-refresh-token')
      ? req.universalCookies.get('x-refresh-token')
      : null;
github internetErik / keystone4-universal-react / server / routes / view / login.js View on Github external
exports = module.exports = (request, response) => {

  // handle redirect if we aren't logged in
  if(request.session.loggedIn) {
    response.redirect(301, '/');
    return;
  }

  // generate a string that we will render to the page
  const html = renderToString();

  // get values for head: title, meta tags
  const head = Helmet.renderStatic();

  // render the page, and send it to the client
  response.send(renderLayout(head, html, 'login', {}, !!(request.user && request.user.isAdmin)))
};
github plone / volto / src / helpers / Html / Html.jsx View on Github external
export const Html = ({ assets, component, store }) => {
  const content = ReactDOM.renderToString(component);
  const head = Helmet.rewind();
  // Workaround for testing
  // Otherwise we get TypeError: _reactHelmet2.default.renderStatic is not a function
  const helmet =
    process.env.NODE_ENV === 'production' ? Helmet.renderStatic() : null;
  const bodyAttrs = helmet && helmet.bodyAttributes.toComponent();

  return (
    
      
        {head.base.toComponent()}
        {head.title.toComponent()}
        {head.meta.toComponent()}
        {head.link.toComponent()}
        {head.script.toComponent()}

        
        
        {/* styles (will be present only in production with webpack extract text plugin) */}
        {Object.keys(assets.styles).map(style => (
github webiny / webiny-js / packages / demo-site / server / server.js View on Github external
const client = createClient(req);

    const app = (
        
            
                
            
        
    );

    // Executes all graphql queries for the current state of application
    await getDataFromTree(app);
    const content = ReactDOMServer.renderToStaticMarkup(app);
    const state = client.extract();
    const helmet = Helmet.renderStatic();
    const html = ReactDOMServer.renderToStaticMarkup(
        
    );
    res.status(200);
    res.send(`${html}`);
    res.end();
});
github arnoldczhang / fe-guide / src / koa / example / koa-ssr / src / server.ts View on Github external
router.get("/*", (ctx: Koa.Context, next) => {
  const context = {};
  const { req } = ctx;
  const store: Store = createStore();

  try {
    store.dispatch(initializeSession());
    const reactDom = getRenderDom(context, req, store);
    const reduxState = store.getState();
    const helmetData = Helmet.renderStatic();

    ctx.status = 200;
    ctx.set("Content-Type", "text/html");
    ctx.body = htmlTemplate(reactDom, reduxState, helmetData);
  } catch (err) {
    console.log(err);
    next();
  }
});
github mtmr0x / isomorphic-boilerplate / src / server / routes / index.js View on Github external
}).then(() => {
    const componentHTML = renderToString(
      
        
          {routes}
        
      
    );

    const head = Helmet.renderStatic();
    const html = renderHTML(
      componentHTML,
      store.getState(),
      webpackIsomorphicTools.assets(),
      head,
    );

    return { html };
  }).then(({ html }) => {
    if (req.url === '/404') {
github diegohaz / arc / src / components / Html.js View on Github external
const Html = ({
  styles, assets, state, content,
}) => {
  const helmet = Helmet.renderStatic()
  const htmlAttrs = helmet.htmlAttributes.toComponent()
  const bodyAttrs = helmet.bodyAttributes.toComponent()

  return (
    
      
        {helmet.title.toComponent()}
        {helmet.meta.toComponent()}
        {helmet.link.toComponent()}
        {assets.css.map(path => )}
        {styles}
      
      
        <main id="app">
        </main>
github NDLANO / learningpath-frontend / src / server / helpers / render.js View on Github external
export function renderPage(Page, assets, state = {}) {
  const { html, ids, css } = extractCritical(renderToString(Page));
  const helmet = Helmet.renderStatic();
  return {
    html,
    helmet,
    assets,
    state,
    css,
    data: {
      ids,
      config,
    },
  };
}
github wix / pro-gallery / packages / ssr-simulator / server / renderServerSideApp.js View on Github external
function renderApp(ServerApp, data, req, res) {
  const context = {};
  const modules = [];

  const markup = ReactDOMServer.renderToString(
     modules.push(moduleName)}&gt;
      
    
  );

  if (context.url) {
    res.redirect(context.url);
  } else {
    const fullMarkup = indexHtml({
      helmet: Helmet.renderStatic(),
      serverData: data,
      bundles: getBundles(stats, modules),
      markup
    });

    res.status(200).send(fullMarkup);
  }
}
github Hashnode / Uphack / pages / _document.js View on Github external
static getInitialProps({ renderPage, req }) {
    const { html, head, errorHtml, chunks } = renderPage();
    const helmet = Helmet.renderStatic();
    return { html, head, errorHtml, chunks, helmet }
  }