renderStatic的头盔错误

时间:2018-10-10 02:17:06

标签: reactjs meteor react-helmet

我正在尝试在流星应用程序中使用SSR设置头盔npm,但出现错误Error running template: TypeError: Cannot read property 'renderStatic' of undefined at sink。我是使用SSR的新手,所以我没有关注我在这里缺少的内容。问题。

路径:server/main.js

import React from "react";
import PropTypes from 'prop-types';
import { onPageLoad } from "meteor/server-render";
import { renderToNodeStream } from "react-dom/server";
import { ServerStyleSheet } from "styled-components"
import { Helmet } from 'react-helmet';  

import App from "/imports/server/app/App";

onPageLoad(sink => {
  const sheet = new ServerStyleSheet();
  const appJSX = sheet.collectStyles(
    <App location={sink.request.url} />
  );

  App.propTypes = {
    location: PropTypes.object,
  };


  const htmlStream = sheet.interleaveWithNodeStream(
    renderToNodeStream(appJSX)
    );

  sink.renderIntoElementById("react-root-app", htmlStream);

  const helmet = Helmet.renderStatic();
  sink.appendToHead(helmet.meta.toString());
  sink.appendToHead(helmet.title.toString());

});

2 个答案:

答案 0 :(得分:2)

由于头盔是默认导出,因此您需要以类似方式导入

var // nearest enclosing function
let // nearest enclosing block

但不是

  import Helmet from 'react-helmet';  

答案 1 :(得分:0)

但是,最新版本没有默认导入。

您必须这样导入它。

import { Helmet } from 'react-helmet';  

这是根据版本

"react-helmet": "^6.0.0",