【问题标题】:Reactstrap not working with Razzle Server Side RenderingReactstrap 不适用于 Razzle 服务器端渲染
【发布时间】:2021-12-22 19:39:36
【问题描述】:

我们正在将现有的 React 应用程序(使用 CRA 创建)转换为 Razzle 应用程序,以便为某些页面提供服务器端渲染。

我们能够通过迁移完成许多事情,但现在卡住了 Reactstrap 组件(仅检查 Button 组件)无法在服务器端呈现。它们在客户端渲染时工作正常。

我得到的错误是,

"error":"元素类型无效:应为字符串(对于内置 组件)或类/函数(用于复合组件),但得到: 不明确的。您可能忘记从文件中导出组件 它是在中定义的,或者您可能混淆了默认值和命名 进口。”

代码,

import React from "react";
import { Button } from "reactstrap";

const AboutPage = () => {
  return (
    <>
      <div>This is about page</div>
      <div>
        <Button color="danger">Save</Button>
      </div>
    </>
  );
};

export default AboutPage;

我不确定它是否需要对 razzle webpack 配置进行任何更改才能使其正常工作。如果有人成功地将 Reactstrap 组件与 Razzle SSR 一起使用,那么还需要哪些额外步骤才能使其正常工作?

谢谢。

【问题讨论】:

    标签: reactjs server-side-rendering reactstrap razzle


    【解决方案1】:

    你可以尝试使用这样的导入语句吗,

    import { Button } from "reactstrap";
    

    你可以尝试用这个重新创建应用程序吗,我认为安装了更新的 react

    npx create-razzle-app YOUR_APP_NAME --example basic
    

    【讨论】:

    • 不,它不起作用。 Reactstrap 没有默认导出的 Button 组件,像这样导入。
    • @Wijitha 你能在 github 问题上寻求帮助吗https://github.com/jaredpalmer/razzle 他们可能会帮助你
    • @Ashisk 当然可以。谢谢。
    猜你喜欢
    • 2019-08-05
    • 1970-01-01
    • 2021-01-14
    • 2020-10-22
    • 2022-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多